diff options
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 51 |
1 files changed, 12 insertions, 39 deletions
@@ -188,36 +188,8 @@ copyFile( const char *srcName, const char *destName, | |||
188 | #endif | 188 | #endif |
189 | 189 | ||
190 | 190 | ||
191 | #ifdef BB_MV | ||
192 | /* | ||
193 | * Build a path name from the specified directory name and file name. | ||
194 | * If the directory name is NULL, then the original fileName is returned. | ||
195 | * The built path is in a static area, and is overwritten for each call. | ||
196 | */ | ||
197 | char *buildName(const char *dirName, const char *fileName) | ||
198 | { | ||
199 | const char *cp; | ||
200 | static char buf[PATH_LEN]; | ||
201 | |||
202 | if ((dirName == NULL) || (*dirName == '\0')) { | ||
203 | strcpy(buf, fileName); | ||
204 | return buf; | ||
205 | } | ||
206 | |||
207 | cp = strrchr(fileName, '/'); | ||
208 | |||
209 | if (cp) | ||
210 | fileName = cp + 1; | ||
211 | |||
212 | strcpy(buf, dirName); | ||
213 | strcat(buf, "/"); | ||
214 | |||
215 | return buf; | ||
216 | } | ||
217 | #endif | ||
218 | |||
219 | |||
220 | 191 | ||
192 | #ifdef BB_TAR | ||
221 | /* | 193 | /* |
222 | * Return the standard ls-like mode string from a file mode. | 194 | * Return the standard ls-like mode string from a file mode. |
223 | * This is static and so is overwritten on each call. | 195 | * This is static and so is overwritten on each call. |
@@ -239,15 +211,10 @@ const char *modeString(int mode) | |||
239 | buf[0] = 'b'; | 211 | buf[0] = 'b'; |
240 | if (S_ISFIFO(mode)) | 212 | if (S_ISFIFO(mode)) |
241 | buf[0] = 'p'; | 213 | buf[0] = 'p'; |
242 | #ifdef S_ISLNK | ||
243 | if (S_ISLNK(mode)) | 214 | if (S_ISLNK(mode)) |
244 | buf[0] = 'l'; | 215 | buf[0] = 'l'; |
245 | #endif | ||
246 | #ifdef S_ISSOCK | ||
247 | if (S_ISSOCK(mode)) | 216 | if (S_ISSOCK(mode)) |
248 | buf[0] = 's'; | 217 | buf[0] = 's'; |
249 | #endif | ||
250 | |||
251 | /* | 218 | /* |
252 | * Now fill in the normal file permissions. | 219 | * Now fill in the normal file permissions. |
253 | */ | 220 | */ |
@@ -284,7 +251,6 @@ const char *modeString(int mode) | |||
284 | } | 251 | } |
285 | 252 | ||
286 | 253 | ||
287 | #ifdef BB_TAR | ||
288 | /* | 254 | /* |
289 | * Get the time string to be used for a file. | 255 | * Get the time string to be used for a file. |
290 | * This is down to the minute for new files, but only the date for old files. | 256 | * This is down to the minute for new files, but only the date for old files. |
@@ -467,7 +433,7 @@ int fullRead(int fd, char *buf, int len) | |||
467 | * by the fileAction and dirAction function pointers). | 433 | * by the fileAction and dirAction function pointers). |
468 | */ | 434 | */ |
469 | int | 435 | int |
470 | recursiveAction(const char *fileName, int recurse, int followLinks, | 436 | recursiveAction(const char *fileName, int recurse, int followLinks, int delayDirAction, |
471 | int (*fileAction) (const char *fileName, struct stat* statbuf), | 437 | int (*fileAction) (const char *fileName, struct stat* statbuf), |
472 | int (*dirAction) (const char *fileName, struct stat* statbuf)) | 438 | int (*dirAction) (const char *fileName, struct stat* statbuf)) |
473 | { | 439 | { |
@@ -501,7 +467,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks, | |||
501 | perror(fileName); | 467 | perror(fileName); |
502 | return (FALSE); | 468 | return (FALSE); |
503 | } | 469 | } |
504 | if (dirAction != NULL) { | 470 | if (dirAction != NULL && delayDirAction == FALSE) { |
505 | status = dirAction(fileName, &statbuf); | 471 | status = dirAction(fileName, &statbuf); |
506 | if (status == FALSE) { | 472 | if (status == FALSE) { |
507 | perror(fileName); | 473 | perror(fileName); |
@@ -516,8 +482,8 @@ recursiveAction(const char *fileName, int recurse, int followLinks, | |||
516 | } | 482 | } |
517 | sprintf(nextFile, "%s/%s", fileName, next->d_name); | 483 | sprintf(nextFile, "%s/%s", fileName, next->d_name); |
518 | status = | 484 | status = |
519 | recursiveAction(nextFile, TRUE, followLinks, fileAction, | 485 | recursiveAction(nextFile, TRUE, followLinks, delayDirAction, |
520 | dirAction); | 486 | fileAction, dirAction); |
521 | if (status < 0) { | 487 | if (status < 0) { |
522 | closedir(dir); | 488 | closedir(dir); |
523 | return (FALSE); | 489 | return (FALSE); |
@@ -528,6 +494,13 @@ recursiveAction(const char *fileName, int recurse, int followLinks, | |||
528 | perror(fileName); | 494 | perror(fileName); |
529 | return (FALSE); | 495 | return (FALSE); |
530 | } | 496 | } |
497 | if (dirAction != NULL && delayDirAction == TRUE) { | ||
498 | status = dirAction(fileName, &statbuf); | ||
499 | if (status == FALSE) { | ||
500 | perror(fileName); | ||
501 | return (FALSE); | ||
502 | } | ||
503 | } | ||
531 | } else { | 504 | } else { |
532 | if (fileAction == NULL) | 505 | if (fileAction == NULL) |
533 | return (TRUE); | 506 | return (TRUE); |