-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);
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);
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);
}
if (argc < 3) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
- return (FALSE);
+ exit (FALSE);
}
lastArg = argv[argc - 1];
if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg);
-
- return (FALSE);
+ exit (FALSE);
}
while (argc-- > 2) {
if (unlink (srcName) < 0)
perror (srcName);
}
- return (TRUE);
+ exit (TRUE);
}
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);
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);
}
-static int fileAction(const char *fileName)
+static int fileAction(const char *fileName, struct stat* statbuf)
{
if (pattern==NULL)
fprintf(stdout, "%s\n", fileName);
return( TRUE);
}
-static int dirAction(const char *fileName)
+static int dirAction(const char *fileName, struct stat* statbuf)
{
DIR *dir;
struct dirent *entry;
int find_main(int argc, char **argv)
{
if (argc <= 1) {
- dirAction( ".");
+ dirAction( ".", NULL);
}
/* peel off the "find" */
break;
}
- dirAction( directory);
+ dirAction( directory, NULL);
exit(TRUE);
}
-static int fileAction(const char *fileName)
+static int fileAction(const char *fileName, struct stat* statbuf)
{
if (pattern==NULL)
fprintf(stdout, "%s\n", fileName);
return( TRUE);
}
-static int dirAction(const char *fileName)
+static int dirAction(const char *fileName, struct stat* statbuf)
{
DIR *dir;
struct dirent *entry;
int find_main(int argc, char **argv)
{
if (argc <= 1) {
- dirAction( ".");
+ dirAction( ".", NULL);
}
/* peel off the "find" */
break;
}
- dirAction( directory);
+ dirAction( directory, NULL);
exit(TRUE);
}
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);
if (argc < 3) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
- return (FALSE);
+ exit (FALSE);
}
lastArg = argv[argc - 1];
if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg);
-
- return (FALSE);
+ exit (FALSE);
}
while (argc-- > 2) {
if (unlink (srcName) < 0)
perror (srcName);
}
- return (TRUE);
+ exit (TRUE);
}
if (stat(name, &statBuf) < 0)
return FALSE;
-
- return S_ISDIR(statBuf.st_mode);
+ if (S_ISDIR(statBuf.st_mode))
+ return TRUE;
+ return(FALSE);
}
*/
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;
if (recurse == FALSE) {
if (S_ISDIR(statbuf.st_mode)) {
if (dirAction != NULL)
- return (dirAction(fileName));
+ return (dirAction(fileName, &statbuf));
else
return (TRUE);
}
return (FALSE);
}
if (dirAction != NULL) {
- status = dirAction(fileName);
+ status = dirAction(fileName, &statbuf);
if (status == FALSE) {
perror(fileName);
return (FALSE);
if (fileAction == NULL)
return (TRUE);
else
- return (fileAction(fileName));
+ return (fileAction(fileName, &statbuf));
}
return (TRUE);
}