Ticket #3089 (closed defect: fixed)

Opened 8 weeks ago

Last modified 8 weeks ago

readdir(dirp)->d_type does not work on solaris

Reported by: Neuron Owned by: mutt-dev
Priority: blocker Milestone:
Component: mutt Version: 1.5.18
Keywords: solaris stat mutt_rmtree Cc:

Description

Hi,

        /usr/dist/share/sunstudio_i386/SUNWspro/bin/cc -DPKGDATADIR=\"/opt/mutt-vlad/share/mutt\" -DSYSCONFDIR=\"/opt/mutt-vlad/etc\" -DBINDIR=\"/opt/mutt-vlad/bin\" -DMUTTLOCALEDIR=\"/opt/mutt-vlad/share/locale\" -DHAVE_CONFIG_H=1 -I.  -I. -I. -I./imap  -Iintl -I/tmp/vm156888/build/ncurses-5.6/include -I/tmp/vm156888/build/openssl-0.9.8h/include -I/tmp/vm156888/build/gdbm-1.8.3/include -I/tmp/vm156888/build/libiconv-1.12/include -I./intl -I/tmp/vm156888/build/libidn-1.8/include  -fast -xarch=generic -Dxxx -I/tmp/vm156888/build/gdbm-1.8.3/include -c lib.c
"lib.c", line 600: undefined struct/union member: d_type
"lib.c", line 600: undefined symbol: DT_DIR
cc: acomp failed for lib.c
make[2]: *** [lib.o] Error 2
make[2]: Leaving directory `/store/rcs/mp'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/store/rcs/mp'
make: *** [all] Error 2

================================== man dirent ==================================
Headers                                           dirent.h(3HEAD)



NAME
     dirent.h, dirent - format of directory entries

SYNOPSIS
     #include <dirent.h>


DESCRIPTION
     The internal  format  of  directories  is  unspecified.  The
     <dirent.h> header defines the following type:

     DIR    A type representing a directory stream.



     The header also defines the structure dirent, which includes
     the following members:

       ino_t d_ino        /* file serial number */
       char  d_name[]     /* name of entry */

     The type ino_t is defined as described in <sys/types.h>. See
     types(3HEAD).
...
================================================================================

For Solaris it would work better to use stat(2). Please note that I compiled this, but not tested ...

diff --git a/lib.c b/lib.c
--- a/lib.c
+++ b/lib.c
@@ -41,6 +41,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <pwd.h>
+#include <sys/types.h>
 #include <dirent.h>
 
 #ifdef HAVE_SYSEXITS_H
@@ -583,6 +584,7 @@
   DIR* dirp;
   struct dirent* de;
   char cur[_POSIX_PATH_MAX];
+  struct stat statbuf;
   int rc = 0;
 
   if (!(dirp = opendir (path)))
@@ -597,7 +599,14 @@
 
     snprintf (cur, sizeof (cur), "%s/%s", path, de->d_name);
     /* XXX make nonrecursive version */
-    if (de->d_type == DT_DIR)
+
+    if (stat(cur, &statbuf) == -1)
+    {
+      rc = 1;
+      continue;
+    }
+
+    if (S_ISDIR (statbuf.st_mode))
       rc |= mutt_rmtree (cur);
     else
       rc |= unlink (cur);

Thank you

-- 
  Vlad

Attachments

part0001.pgp (193 bytes) - added by Vladimir Marek 8 weeks ago.
Added by email2trac

Change History

Changed 8 weeks ago by Neuron

  • status changed from new to closed
  • resolution set to fixed

(In [f72fce68ca19]) Use stat() instead of dirent->d_type to test for directory. Closes #3089.

Changed 8 weeks ago by Vladimir Marek

Added by email2trac

Changed 8 weeks ago by Vladimir Marek

> Changes (by Neuron):
> 
>   * status:  new => closed
>   * resolution:  => fixed
> 
> Comment:
> 
>  (In [f72fce68ca19]) Use stat() instead of dirent->d_type to test for
>  directory. Closes #3089.

Thank you, that helped
Note: See TracTickets for help on using tickets.