pcg@aber-cs.UUCP (Piercarlo Grandi) (01/06/90)
The rh tree walker is a fine replacement for find(1), but it does not work well on System V machines because of a problem with filenames that are exactly DIRSIZ characters long and are thus not null terminated. The problem is fixed here. We also take the opportunity to do a few cosmetic fixes. =================================================================== RCS file: rhdir.c,v retrieving revision 1.1 diff -c -r1.1 rhdir.c *** /tmp/,RCSt1a22740 Sun Dec 24 20:06:22 1989 --- rhdir.c Sun Dec 24 20:06:19 1989 *************** *** 20,26 **** #define isdirect(b) ((b&S_IFMT)==S_IFDIR) ! #if SUN #include <dirent.h> #define MAXPATHLEN 255 --- 20,26 ---- #define isdirect(b) ((b&S_IFMT)==S_IFDIR) ! #if SUN || SYSV #include <dirent.h> #define MAXPATHLEN 255 *************** *** 38,44 **** #endif ! #if XENIX || SYSV #include <sys/dir.h> #define MAXPATHLEN 255 --- 38,44 ---- #endif ! #if XENIX #include <sys/dir.h> #define MAXPATHLEN 255 *************** *** 110,119 **** } } /* ---------------------------------------------------------------------- * ftw: * Entry point to do the search, ftw is a front end ! * to the recursive fwt1. * ftw() places some of the arguments to global variables * so that they arguments would not have to be passed around to * ftw1(). --- 110,121 ---- } } + #if !SYSV + /* ---------------------------------------------------------------------- * ftw: * Entry point to do the search, ftw is a front end ! * to the recursive ftw1. * ftw() places some of the arguments to global variables * so that they arguments would not have to be passed around to * ftw1(). *************** *** 140,152 **** (*func)(f,&statbuf); ! if( isproper( statbuf.st_mode ) ) fwt1(depth); return(0); } /* ---------------------------------------------------------------------- ! * fwt1: * 2 versions of this routine currently live here: * XENIX/SYSV, and SUN/BSD. They both differ in * the manner in which they access directories. --- 142,154 ---- (*func)(f,&statbuf); ! if( isproper( statbuf.st_mode ) ) ftw1(depth); return(0); } /* ---------------------------------------------------------------------- ! * ftw1: * 2 versions of this routine currently live here: * XENIX/SYSV, and SUN/BSD. They both differ in * the manner in which they access directories. *************** *** 153,170 **** * Any chnages needed to work on another system * should only have to made for this routine. * ! * Below is the SUN/BSD version of fwt1() * -------------------------------------- * */ ! #if SUN || BSD ! static fwt1(depth) int depth; { ! #if SUN DIR *dirp; struct dirent *dp; #else --- 155,172 ---- * Any chnages needed to work on another system * should only have to made for this routine. * ! * Below is the SUN/BSD version of ftw1() * -------------------------------------- * */ ! #if SUN || BSD || SYSV ! static ftw1(depth) int depth; { ! #if SUN || SYSV DIR *dirp; struct dirent *dp; #else *************** *** 189,195 **** if( isproper( statbuf.st_mode ) ) { basep[ strlen(dp->d_name) ] = '/'; basep[ strlen(dp->d_name)+1 ] = '\0'; ! fwt1(depth-1); } } closedir(dirp); --- 191,197 ---- if( isproper( statbuf.st_mode ) ) { basep[ strlen(dp->d_name) ] = '/'; basep[ strlen(dp->d_name)+1 ] = '\0'; ! ftw1(depth-1); } } closedir(dirp); *************** *** 203,215 **** * meant for XENIX/SYSV type systems that do directory reading * "by hand" * ! * Below is the XENIX/SYSV version of fwt1() * -------------------------------------- */ ! #if XENIX || SYSV ! static fwt1(depth) int depth; { char *basep; --- 205,217 ---- * meant for XENIX/SYSV type systems that do directory reading * "by hand" * ! * Below is the XENIX/SYSV version of ftw1() * -------------------------------------- */ ! #if XENIX ! static ftw1(depth) int depth; { char *basep; *************** *** 229,245 **** if( dp.d_name[0]=='.' && dp.d_name[1]=='\0' ) continue; if( dp.d_name[0]=='.' && dp.d_name[1]=='.' && dp.d_name[2]=='\0' ) continue; ! strcpy(basep,dp.d_name); if( lstat(filename,&statbuf) < 0 ) continue; (*func)(filename,&statbuf); if( isproper( statbuf.st_mode ) ) { basep[ strlen(dp.d_name) ] = '/'; basep[ strlen(dp.d_name)+1 ] = '\0'; ! fwt1(depth-1); } } fclose(dirp); *basep = '\0'; } #endif --- 231,250 ---- if( dp.d_name[0]=='.' && dp.d_name[1]=='\0' ) continue; if( dp.d_name[0]=='.' && dp.d_name[1]=='.' && dp.d_name[2]=='\0' ) continue; ! strncpy(basep,dp.d_name,DIRSIZ); ! basep[DIRSIZ] = '\0'; if( lstat(filename,&statbuf) < 0 ) continue; (*func)(filename,&statbuf); if( isproper( statbuf.st_mode ) ) { basep[ strlen(dp.d_name) ] = '/'; basep[ strlen(dp.d_name)+1 ] = '\0'; ! ftw1(depth-1); } } fclose(dirp); *basep = '\0'; } + + #endif #endif -- Piercarlo "Peter" Grandi | ARPA: pcg%cs.aber.ac.uk@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcvax!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk