handle broken readdir() on Solaris 2.6 (it returns the name offset by

2 characters!)
This commit is contained in:
Andrew Tridgell committed 1998-05-06 07:00:38 +00:00
1 parent 73233f0f12
commit d6e6ecbdbf
5 files changed
+48 -22

No files matched your search

+7
View 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)
+4 -3
View File
@@ -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);
}
+5 -4
View File
@@ -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);
+14 -15
View File
@@ -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
+18
View File
@@ -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;
}