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 65a40a5..f740073 100644 (file)
@@ -76,4 +76,11 @@ AC_TRY_COMPILE([#include <sys/types.h>
 echo yes;AC_DEFINE(HAVE_UTIMBUF), 
 echo no)
 
 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)
 AC_OUTPUT(Makefile lib/dummy)
diff --git a/flist.c b/flist.c
index 80754e9..5303873 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)) {
        }  
        
        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;
                        continue;
-               strncpy(p,di->d_name,MAXPATHLEN-(l+1));
+               strncpy(p,dname,MAXPATHLEN-(l+1));
                send_file_name(f,flist,fname,recurse,FLAG_DELETE);
        }
 
                send_file_name(f,flist,fname,recurse,FLAG_DELETE);
        }
 
diff --git a/rsync.c b/rsync.c
index 463d428..16a7a31 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)) {
        }
 
        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;
                        continue;
-               strncpy(buf, fname, (MAXPATHLEN-strlen(di->d_name))-2);
+               strncpy(buf, fname, (MAXPATHLEN-strlen(dname))-2);
                strcat(buf, "/");
                strcat(buf, "/");
-               strcat(buf, di->d_name);
+               strcat(buf, dname);
                buf[MAXPATHLEN-1] = 0;
                if (verbose > 0)
                        fprintf(FINFO,"deleting %s\n", buf);
                buf[MAXPATHLEN-1] = 0;
                if (verbose > 0)
                        fprintf(FINFO,"deleting %s\n", buf);
diff --git a/rsync.h b/rsync.h
index 3418b81..1491046 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;
 }
 
        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"
 
 #include "byteorder.h"
 #include "version.h"
@@ -306,21 +320,6 @@ extern char *sys_errlist[];
 # define strrchr                rindex
 #endif
 
 # 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
 #ifndef HAVE_ERRNO_DECL
 extern int errno;
 #endif
index a004d9d..5bf3e47 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
 }
        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;
+}