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;
if (stat(fileName, &statBuf) < 0) {
switch (whichApp) {
case CHGRP_APP:
case CHOWN_APP:
if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statBuf.st_uid), gid) < 0)
return( TRUE);
case CHMOD_APP:
fprintf(stderr, "%s, %d\n", fileName, mode);
if (chmod(fileName, mode))
return( TRUE);
}
switch (whichApp) {
case CHGRP_APP:
case CHOWN_APP:
if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statbuf->st_uid), gid) < 0)
return( TRUE);
case CHMOD_APP:
fprintf(stderr, "%s, %d\n", fileName, mode);
if (chmod(fileName, mode))
return( TRUE);
}
perror(fileName);
return( FALSE);

View File

@ -41,21 +41,24 @@ static int preserveFlag = FALSE;
static const char *srcName;
static const char *destName;
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];
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));
}
extern int cp_main(int argc, char **argv)
{
int dirFlag;
if (argc < 3) {
fprintf(stderr, "Usage: %s", cp_usage);
exit (FALSE);
@ -91,10 +94,9 @@ extern int cp_main(int argc, char **argv)
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
if ((argc > 3) && !dirFlag) {
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}

View File

@ -41,7 +41,7 @@ extern int mv_main (int argc, char **argv)
if (argc < 3) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
return (FALSE);
exit (FALSE);
}
lastArg = argv[argc - 1];
@ -49,8 +49,7 @@ extern int mv_main (int argc, char **argv)
if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg);
return (FALSE);
exit (FALSE);
}
while (argc-- > 2) {
@ -80,5 +79,5 @@ extern int mv_main (int argc, char **argv)
if (unlink (srcName) < 0)
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 *destName;
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];
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));
}
extern int cp_main(int argc, char **argv)
{
int dirFlag;
if (argc < 3) {
fprintf(stderr, "Usage: %s", cp_usage);
exit (FALSE);
@ -91,10 +94,9 @@ extern int cp_main(int argc, char **argv)
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
if ((argc > 3) && !dirFlag) {
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
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)
fprintf(stdout, "%s\n", fileName);
@ -44,7 +44,7 @@ static int fileAction(const char *fileName)
return( TRUE);
}
static int dirAction(const char *fileName)
static int dirAction(const char *fileName, struct stat* statbuf)
{
DIR *dir;
struct dirent *entry;
@ -70,7 +70,7 @@ static int dirAction(const char *fileName)
int find_main(int argc, char **argv)
{
if (argc <= 1) {
dirAction( ".");
dirAction( ".", NULL);
}
/* peel off the "find" */
@ -120,7 +120,7 @@ int find_main(int argc, char **argv)
break;
}
dirAction( directory);
dirAction( directory, NULL);
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)
fprintf(stdout, "%s\n", fileName);
@ -44,7 +44,7 @@ static int fileAction(const char *fileName)
return( TRUE);
}
static int dirAction(const char *fileName)
static int dirAction(const char *fileName, struct stat* statbuf)
{
DIR *dir;
struct dirent *entry;
@ -70,7 +70,7 @@ static int dirAction(const char *fileName)
int find_main(int argc, char **argv)
{
if (argc <= 1) {
dirAction( ".");
dirAction( ".", NULL);
}
/* peel off the "find" */
@ -120,7 +120,7 @@ int find_main(int argc, char **argv)
break;
}
dirAction( directory);
dirAction( directory, NULL);
exit(TRUE);
}

View File

@ -122,8 +122,8 @@ void freeChunks(void);
int fullWrite(int fd, const char *buf, int len);
int fullRead(int fd, char *buf, int len);
int recursiveAction(const char *fileName, int recurse, int followLinks,
int (*fileAction) (const char *fileName),
int (*dirAction) (const char *fileName));
int (*fileAction) (const char *fileName, struct stat* statbuf),
int (*dirAction) (const char *fileName, struct stat* statbuf));
int match(const char* text, const char * pattern);
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) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
return (FALSE);
exit (FALSE);
}
lastArg = argv[argc - 1];
@ -49,8 +49,7 @@ extern int mv_main (int argc, char **argv)
if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg);
return (FALSE);
exit (FALSE);
}
while (argc-- > 2) {
@ -80,5 +79,5 @@ extern int mv_main (int argc, char **argv)
if (unlink (srcName) < 0)
perror (srcName);
}
return (TRUE);
exit (TRUE);
}

View File

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