handle broken readdir() on Solaris 2.6 (it returns the name offset by
authorAndrew Tridgell <tridge@samba.org>
Wed, 6 May 1998 07:00:38 +0000 (07:00 +0000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 6 May 1998 07:00:38 +0000 (07:00 +0000)
2 characters!)

configure.in
flist.c
rsync.c
rsync.h
syscall.c

index 65a40a567ef2c21d2c6a19e33566c589c22675fb..f7400730d399382300bd3a1f38913749eaa39882 100644 (file)
@@ -76,4 +76,11 @@ AC_TRY_COMPILE([#include <sys/types.h>
 echo yes;AC_DEFINE(HAVE_UTIMBUF), 
 echo no)
 
+echo $ac_n "checking for broken readdir ... $ac_c"
+AC_TRY_COMPILE([#include <sys/types.h>
+#include <utime.h>],
+[struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; return utime("foo.c",&tbuf);],
+echo yes;AC_DEFINE(HAVE_UTIMBUF), 
+echo no)
+
 AC_OUTPUT(Makefile lib/dummy)
diff --git a/flist.c b/flist.c
index 80754e95e1fec97c5a421b9c21985bec3166a0d6..530387392bf17b4a861ebd6c79a6649712947698 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -538,10 +538,11 @@ static void send_directory(int f,struct file_list *flist,char *dir)
        }  
        
        for (di=readdir(d); di; di=readdir(d)) {
-               if (strcmp(di->d_name,".")==0 ||
-                   strcmp(di->d_name,"..")==0)
+               char *dname = d_name(di);
+               if (strcmp(dname,".")==0 ||
+                   strcmp(dname,"..")==0)
                        continue;
-               strncpy(p,di->d_name,MAXPATHLEN-(l+1));
+               strncpy(p,dname,MAXPATHLEN-(l+1));
                send_file_name(f,flist,fname,recurse,FLAG_DELETE);
        }
 
diff --git a/rsync.c b/rsync.c
index 463d428116d1f40e6426e5cb2c03772a3772211e..16a7a31b009a8629faddf2c28a788f9f3fc0390b 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -107,12 +107,13 @@ static int delete_file(char *fname)
        }
 
        for (di=readdir(d); di; di=readdir(d)) {
-               if (strcmp(di->d_name,".")==0 ||
-                   strcmp(di->d_name,"..")==0)
+               char *dname = d_name(di);
+               if (strcmp(dname,".")==0 ||
+                   strcmp(dname,"..")==0)
                        continue;
-               strncpy(buf, fname, (MAXPATHLEN-strlen(di->d_name))-2);
+               strncpy(buf, fname, (MAXPATHLEN-strlen(dname))-2);
                strcat(buf, "/");
-               strcat(buf, di->d_name);
+               strcat(buf, dname);
                buf[MAXPATHLEN-1] = 0;
                if (verbose > 0)
                        fprintf(FINFO,"deleting %s\n", buf);
diff --git a/rsync.h b/rsync.h
index 3418b8170b34748c1cab74de4645c231e73302d5..149104627757ef85b3cc5db4e2d768fe1a888247 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -290,6 +290,20 @@ static inline int flist_up(struct file_list *flist, int i)
        return i;
 }
 
+#if HAVE_DIRENT_H
+# include <dirent.h>
+#else
+# define dirent direct
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
 
 #include "byteorder.h"
 #include "version.h"
@@ -306,21 +320,6 @@ extern char *sys_errlist[];
 # define strrchr                rindex
 #endif
 
-#if HAVE_DIRENT_H
-# include <dirent.h>
-#else
-# define dirent direct
-# if HAVE_SYS_NDIR_H
-#  include <sys/ndir.h>
-# endif
-# if HAVE_SYS_DIR_H
-#  include <sys/dir.h>
-# endif
-# if HAVE_NDIR_H
-#  include <ndir.h>
-# endif
-#endif
-
 #ifndef HAVE_ERRNO_DECL
 extern int errno;
 #endif
index a004d9d37b764b8814683e168b083df40b329e10..5bf3e476dde098a99f9a1e8845470462faeed85e 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -133,3 +133,21 @@ OFF_T do_lseek(int fd, OFF_T offset, int whence)
        return lseek(fd, offset, whence);
 #endif
 }
+
+char *d_name(struct dirent *di)
+{
+#if defined(SunOS) && SunOS >= 50
+       static int first = 1;
+       static int broken;
+       if (first) {
+               first = 0;
+               if (!di->d_name[0] && strcmp(".", di->d_name-2)==0) {
+                       fprintf(stderr,"WARNING: broken readdir\n");
+                       broken = 1;
+               }
+       }
+       if (broken)
+               return (di->d_name - 2);
+#endif
+       return di->d_name;
+}