Some fixes and such

This commit is contained in:
Eric Andersen 1999-10-17 05:43:39 +00:00
parent cb6e25655f
commit 9b58718889
9 changed files with 50 additions and 50 deletions

View File

@ -49,20 +49,17 @@ static const char chmod_usage[] = "[-R] MODE[,MODE]... FILE...\n"
static int fileAction(const char *fileName) static int fileAction(const char *fileName, struct stat* statbuf)
{ {
struct stat statBuf; switch (whichApp) {
if (stat(fileName, &statBuf) < 0) { case CHGRP_APP:
switch (whichApp) { case CHOWN_APP:
case CHGRP_APP: if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statbuf->st_uid), gid) < 0)
case CHOWN_APP: return( TRUE);
if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statBuf.st_uid), gid) < 0) case CHMOD_APP:
return( TRUE); fprintf(stderr, "%s, %d\n", fileName, mode);
case CHMOD_APP: if (chmod(fileName, mode))
fprintf(stderr, "%s, %d\n", fileName, mode); return( TRUE);
if (chmod(fileName, mode))
return( TRUE);
}
} }
perror(fileName); perror(fileName);
return( FALSE); return( FALSE);

View File

@ -41,21 +41,24 @@ static int preserveFlag = FALSE;
static const char *srcName; static const char *srcName;
static const char *destName; static const char *destName;
static const char *skipName; static const char *skipName;
static int dirFlag = FALSE;
static int fileAction(const char *fileName) static int fileAction(const char *fileName, struct stat* statbuf)
{ {
char newdestName[NAME_MAX]; char newdestName[NAME_MAX];
strcpy(newdestName, destName); strcpy(newdestName, destName);
strcat(newdestName, strstr(fileName, skipName)); if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks)); return (copyFile(fileName, newdestName, preserveFlag, followLinks));
} }
extern int cp_main(int argc, char **argv) extern int cp_main(int argc, char **argv)
{ {
int dirFlag;
if (argc < 3) { if (argc < 3) {
fprintf(stderr, "Usage: %s", cp_usage); fprintf(stderr, "Usage: %s", cp_usage);
exit (FALSE); exit (FALSE);
@ -91,10 +94,9 @@ extern int cp_main(int argc, char **argv)
destName = argv[argc - 1]; destName = argv[argc - 1];
dirFlag = isDirectory(destName); dirFlag = isDirectory(destName);
if ((argc > 3) && !dirFlag) { if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName); fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE); exit (FALSE);
} }

View File

@ -41,7 +41,7 @@ extern int mv_main (int argc, char **argv)
if (argc < 3) { if (argc < 3) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage); fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
return (FALSE); exit (FALSE);
} }
lastArg = argv[argc - 1]; lastArg = argv[argc - 1];
@ -49,8 +49,7 @@ extern int mv_main (int argc, char **argv)
if ((argc > 3) && !dirFlag) { if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg); fprintf (stderr, "%s: not a directory\n", lastArg);
exit (FALSE);
return (FALSE);
} }
while (argc-- > 2) { while (argc-- > 2) {
@ -80,5 +79,5 @@ extern int mv_main (int argc, char **argv)
if (unlink (srcName) < 0) if (unlink (srcName) < 0)
perror (srcName); perror (srcName);
} }
return (TRUE); exit (TRUE);
} }

14
cp.c
View File

@ -41,21 +41,24 @@ static int preserveFlag = FALSE;
static const char *srcName; static const char *srcName;
static const char *destName; static const char *destName;
static const char *skipName; static const char *skipName;
static int dirFlag = FALSE;
static int fileAction(const char *fileName) static int fileAction(const char *fileName, struct stat* statbuf)
{ {
char newdestName[NAME_MAX]; char newdestName[NAME_MAX];
strcpy(newdestName, destName); strcpy(newdestName, destName);
strcat(newdestName, strstr(fileName, skipName)); if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks)); return (copyFile(fileName, newdestName, preserveFlag, followLinks));
} }
extern int cp_main(int argc, char **argv) extern int cp_main(int argc, char **argv)
{ {
int dirFlag;
if (argc < 3) { if (argc < 3) {
fprintf(stderr, "Usage: %s", cp_usage); fprintf(stderr, "Usage: %s", cp_usage);
exit (FALSE); exit (FALSE);
@ -91,10 +94,9 @@ extern int cp_main(int argc, char **argv)
destName = argv[argc - 1]; destName = argv[argc - 1];
dirFlag = isDirectory(destName); dirFlag = isDirectory(destName);
if ((argc > 3) && !dirFlag) { if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName); fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE); exit (FALSE);
} }

8
find.c
View File

@ -35,7 +35,7 @@ static const char find_usage[] = "find [path...] [expression]\n"
static int fileAction(const char *fileName) static int fileAction(const char *fileName, struct stat* statbuf)
{ {
if (pattern==NULL) if (pattern==NULL)
fprintf(stdout, "%s\n", fileName); fprintf(stdout, "%s\n", fileName);
@ -44,7 +44,7 @@ static int fileAction(const char *fileName)
return( TRUE); return( TRUE);
} }
static int dirAction(const char *fileName) static int dirAction(const char *fileName, struct stat* statbuf)
{ {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
@ -70,7 +70,7 @@ static int dirAction(const char *fileName)
int find_main(int argc, char **argv) int find_main(int argc, char **argv)
{ {
if (argc <= 1) { if (argc <= 1) {
dirAction( "."); dirAction( ".", NULL);
} }
/* peel off the "find" */ /* peel off the "find" */
@ -120,7 +120,7 @@ int find_main(int argc, char **argv)
break; break;
} }
dirAction( directory); dirAction( directory, NULL);
exit(TRUE); exit(TRUE);
} }

View File

@ -35,7 +35,7 @@ static const char find_usage[] = "find [path...] [expression]\n"
static int fileAction(const char *fileName) static int fileAction(const char *fileName, struct stat* statbuf)
{ {
if (pattern==NULL) if (pattern==NULL)
fprintf(stdout, "%s\n", fileName); fprintf(stdout, "%s\n", fileName);
@ -44,7 +44,7 @@ static int fileAction(const char *fileName)
return( TRUE); return( TRUE);
} }
static int dirAction(const char *fileName) static int dirAction(const char *fileName, struct stat* statbuf)
{ {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
@ -70,7 +70,7 @@ static int dirAction(const char *fileName)
int find_main(int argc, char **argv) int find_main(int argc, char **argv)
{ {
if (argc <= 1) { if (argc <= 1) {
dirAction( "."); dirAction( ".", NULL);
} }
/* peel off the "find" */ /* peel off the "find" */
@ -120,7 +120,7 @@ int find_main(int argc, char **argv)
break; break;
} }
dirAction( directory); dirAction( directory, NULL);
exit(TRUE); exit(TRUE);
} }

View File

@ -122,8 +122,8 @@ void freeChunks(void);
int fullWrite(int fd, const char *buf, int len); int fullWrite(int fd, const char *buf, int len);
int fullRead(int fd, char *buf, int len); int fullRead(int fd, char *buf, int len);
int recursiveAction(const char *fileName, int recurse, int followLinks, int recursiveAction(const char *fileName, int recurse, int followLinks,
int (*fileAction) (const char *fileName), int (*fileAction) (const char *fileName, struct stat* statbuf),
int (*dirAction) (const char *fileName)); int (*dirAction) (const char *fileName, struct stat* statbuf));
int match(const char* text, const char * pattern); int match(const char* text, const char * pattern);
const char* timeString(time_t timeVal); const char* timeString(time_t timeVal);

7
mv.c
View File

@ -41,7 +41,7 @@ extern int mv_main (int argc, char **argv)
if (argc < 3) { if (argc < 3) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage); fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
return (FALSE); exit (FALSE);
} }
lastArg = argv[argc - 1]; lastArg = argv[argc - 1];
@ -49,8 +49,7 @@ extern int mv_main (int argc, char **argv)
if ((argc > 3) && !dirFlag) { if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg); fprintf (stderr, "%s: not a directory\n", lastArg);
exit (FALSE);
return (FALSE);
} }
while (argc-- > 2) { while (argc-- > 2) {
@ -80,5 +79,5 @@ extern int mv_main (int argc, char **argv)
if (unlink (srcName) < 0) if (unlink (srcName) < 0)
perror (srcName); perror (srcName);
} }
return (TRUE); exit (TRUE);
} }

View File

@ -46,8 +46,9 @@ int isDirectory(const char *name)
if (stat(name, &statBuf) < 0) if (stat(name, &statBuf) < 0)
return FALSE; return FALSE;
if (S_ISDIR(statBuf.st_mode))
return S_ISDIR(statBuf.st_mode); return TRUE;
return(FALSE);
} }
@ -467,8 +468,8 @@ int fullRead(int fd, char *buf, int len)
*/ */
int int
recursiveAction(const char *fileName, int recurse, int followLinks, recursiveAction(const char *fileName, int recurse, int followLinks,
int (*fileAction) (const char *fileName), int (*fileAction) (const char *fileName, struct stat* statbuf),
int (*dirAction) (const char *fileName)) int (*dirAction) (const char *fileName, struct stat* statbuf))
{ {
int status; int status;
struct stat statbuf; struct stat statbuf;
@ -487,7 +488,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
if (recurse == FALSE) { if (recurse == FALSE) {
if (S_ISDIR(statbuf.st_mode)) { if (S_ISDIR(statbuf.st_mode)) {
if (dirAction != NULL) if (dirAction != NULL)
return (dirAction(fileName)); return (dirAction(fileName, &statbuf));
else else
return (TRUE); return (TRUE);
} }
@ -501,7 +502,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
return (FALSE); return (FALSE);
} }
if (dirAction != NULL) { if (dirAction != NULL) {
status = dirAction(fileName); status = dirAction(fileName, &statbuf);
if (status == FALSE) { if (status == FALSE) {
perror(fileName); perror(fileName);
return (FALSE); return (FALSE);
@ -531,7 +532,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
if (fileAction == NULL) if (fileAction == NULL)
return (TRUE); return (TRUE);
else else
return (fileAction(fileName)); return (fileAction(fileName, &statbuf));
} }
return (TRUE); return (TRUE);
} }