<<< Date Index >>>     <<< Thread Index >>>

[Mutt] #3089: readdir(dirp)->d_type does not work on solaris



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

 {{{
 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
 }}}

-- 
Ticket URL: <http://dev.mutt.org/trac/ticket/3089>