From d6e6ecbdbf0452ec95afc98c2700076e39b4692f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 May 1998 07:00:38 +0000 Subject: [PATCH] handle broken readdir() on Solaris 2.6 (it returns the name offset by 2 characters!) --- configure.in | 7 +++++++ flist.c | 7 ++++--- rsync.c | 9 +++++---- rsync.h | 29 ++++++++++++++--------------- syscall.c | 18 ++++++++++++++++++ 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/configure.in b/configure.in index 65a40a56..f7400730 100644 --- a/configure.in +++ b/configure.in @@ -76,4 +76,11 @@ AC_TRY_COMPILE([#include echo yes;AC_DEFINE(HAVE_UTIMBUF), echo no) +echo $ac_n "checking for broken readdir ... $ac_c" +AC_TRY_COMPILE([#include +#include ], +[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 80754e95..53038739 100644 --- 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 463d4281..16a7a31b 100644 --- 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 3418b817..14910462 100644 --- 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 +#else +# define dirent direct +# if HAVE_SYS_NDIR_H +# include +# endif +# if HAVE_SYS_DIR_H +# include +# endif +# if HAVE_NDIR_H +# include +# 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 -#else -# define dirent direct -# if HAVE_SYS_NDIR_H -# include -# endif -# if HAVE_SYS_DIR_H -# include -# endif -# if HAVE_NDIR_H -# include -# endif -#endif - #ifndef HAVE_ERRNO_DECL extern int errno; #endif diff --git a/syscall.c b/syscall.c index a004d9d3..5bf3e476 100644 --- 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; +} -- 2.34.1