aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /archival/tar.c
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
Major coreutils update.
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/archival/tar.c b/archival/tar.c
index fa1c57512..c39d5787f 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -278,7 +278,7 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
278 header.typeflag = REGTYPE; 278 header.typeflag = REGTYPE;
279 putOctal(header.size, sizeof(header.size), statbuf->st_size); 279 putOctal(header.size, sizeof(header.size), statbuf->st_size);
280 } else { 280 } else {
281 error_msg("%s: Unknown file type", real_name); 281 bb_error_msg("%s: Unknown file type", real_name);
282 return (FALSE); 282 return (FALSE);
283 } 283 }
284 284
@@ -295,9 +295,9 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
295 295
296 /* Now write the header out to disk */ 296 /* Now write the header out to disk */
297 if ((size = 297 if ((size =
298 full_write(tbInfo->tarFd, (char *) &header, 298 bb_full_write(tbInfo->tarFd, (char *) &header,
299 sizeof(struct TarHeader))) < 0) { 299 sizeof(struct TarHeader))) < 0) {
300 error_msg(io_error, real_name); 300 bb_error_msg(bb_msg_io_error, real_name);
301 return (FALSE); 301 return (FALSE);
302 } 302 }
303 /* Pad the header up to the tar block size */ 303 /* Pad the header up to the tar block size */
@@ -368,7 +368,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
368 368
369 /* It is against the rules to archive a socket */ 369 /* It is against the rules to archive a socket */
370 if (S_ISSOCK(statbuf->st_mode)) { 370 if (S_ISSOCK(statbuf->st_mode)) {
371 error_msg("%s: socket ignored", fileName); 371 bb_error_msg("%s: socket ignored", fileName);
372 return (TRUE); 372 return (TRUE);
373 } 373 }
374 374
@@ -377,7 +377,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
377 * the new tarball */ 377 * the new tarball */
378 if (tbInfo->statBuf.st_dev == statbuf->st_dev && 378 if (tbInfo->statBuf.st_dev == statbuf->st_dev &&
379 tbInfo->statBuf.st_ino == statbuf->st_ino) { 379 tbInfo->statBuf.st_ino == statbuf->st_ino) {
380 error_msg("%s: file is the archive; skipping", fileName); 380 bb_error_msg("%s: file is the archive; skipping", fileName);
381 return (TRUE); 381 return (TRUE);
382 } 382 }
383 383
@@ -386,14 +386,14 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
386 static int alreadyWarned = FALSE; 386 static int alreadyWarned = FALSE;
387 387
388 if (alreadyWarned == FALSE) { 388 if (alreadyWarned == FALSE) {
389 error_msg("Removing leading '/' from member names"); 389 bb_error_msg("Removing leading '/' from member names");
390 alreadyWarned = TRUE; 390 alreadyWarned = TRUE;
391 } 391 }
392 header_name++; 392 header_name++;
393 } 393 }
394 394
395 if (strlen(fileName) >= NAME_SIZE) { 395 if (strlen(fileName) >= NAME_SIZE) {
396 error_msg(name_longer_than_foo, NAME_SIZE); 396 bb_error_msg(bb_msg_name_longer_than_foo, NAME_SIZE);
397 return (TRUE); 397 return (TRUE);
398 } 398 }
399 399
@@ -419,21 +419,21 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
419 419
420 /* open the file we want to archive, and make sure all is well */ 420 /* open the file we want to archive, and make sure all is well */
421 if ((inputFileFd = open(fileName, O_RDONLY)) < 0) { 421 if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
422 perror_msg("%s: Cannot open", fileName); 422 bb_perror_msg("%s: Cannot open", fileName);
423 return (FALSE); 423 return (FALSE);
424 } 424 }
425 425
426 /* write the file to the archive */ 426 /* write the file to the archive */
427 while ((size = full_read(inputFileFd, buffer, sizeof(buffer))) > 0) { 427 while ((size = bb_full_read(inputFileFd, buffer, sizeof(buffer))) > 0) {
428 if (full_write(tbInfo->tarFd, buffer, size) != size) { 428 if (bb_full_write(tbInfo->tarFd, buffer, size) != size) {
429 /* Output file seems to have a problem */ 429 /* Output file seems to have a problem */
430 error_msg(io_error, fileName); 430 bb_error_msg(bb_msg_io_error, fileName);
431 return (FALSE); 431 return (FALSE);
432 } 432 }
433 readSize += size; 433 readSize += size;
434 } 434 }
435 if (size == -1) { 435 if (size == -1) {
436 error_msg(io_error, fileName); 436 bb_error_msg(bb_msg_io_error, fileName);
437 return (FALSE); 437 return (FALSE);
438 } 438 }
439 /* Pad the file up to the tar block size */ 439 /* Pad the file up to the tar block size */
@@ -464,7 +464,7 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
464 464
465 /* Make sure there is at least one file to tar up. */ 465 /* Make sure there is at least one file to tar up. */
466 if (include == NULL) { 466 if (include == NULL) {
467 error_msg_and_die("Cowardly refusing to create an empty archive"); 467 bb_error_msg_and_die("Cowardly refusing to create an empty archive");
468 } 468 }
469 469
470 /* Open the tar file for writing. */ 470 /* Open the tar file for writing. */
@@ -477,7 +477,7 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
477 } 477 }
478 478
479 if (tbInfo.tarFd < 0) { 479 if (tbInfo.tarFd < 0) {
480 perror_msg("%s: Cannot open", tarName); 480 bb_perror_msg("%s: Cannot open", tarName);
481 freeHardLinkInfo(&tbInfo.hlInfoHead); 481 freeHardLinkInfo(&tbInfo.hlInfoHead);
482 return (FALSE); 482 return (FALSE);
483 } 483 }
@@ -485,12 +485,12 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
485 /* Store the stat info for the tarball's file, so 485 /* Store the stat info for the tarball's file, so
486 * can avoid including the tarball into itself.... */ 486 * can avoid including the tarball into itself.... */
487 if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0) 487 if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
488 error_msg_and_die(io_error, tarName); 488 bb_error_msg_and_die(bb_msg_io_error, tarName);
489 489
490#ifdef CONFIG_FEATURE_TAR_GZIP 490#ifdef CONFIG_FEATURE_TAR_GZIP
491 if (gzip) { 491 if (gzip) {
492 if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0) { 492 if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0) {
493 perror_msg_and_die("Failed to create gzip pipe"); 493 bb_perror_msg_and_die("Failed to create gzip pipe");
494 } 494 }
495 495
496 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ 496 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
@@ -529,7 +529,7 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
529 529
530 if (n == 0 && vfork_exec_errno != 0) { 530 if (n == 0 && vfork_exec_errno != 0) {
531 errno = vfork_exec_errno; 531 errno = vfork_exec_errno;
532 perror_msg_and_die("Could not exec gzip process"); 532 bb_perror_msg_and_die("Could not exec gzip process");
533 } else if ((n < 0) && (errno == EAGAIN || errno == EINTR)) 533 } else if ((n < 0) && (errno == EAGAIN || errno == EINTR))
534 continue; /* try it again */ 534 continue; /* try it again */
535 break; 535 break;
@@ -538,7 +538,7 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
538 538
539 tbInfo.tarFd = gzipDataPipe[1]; 539 tbInfo.tarFd = gzipDataPipe[1];
540 } else { 540 } else {
541 perror_msg_and_die("Failed to vfork gzip process"); 541 bb_perror_msg_and_die("Failed to vfork gzip process");
542 } 542 }
543 } 543 }
544#endif 544#endif
@@ -567,7 +567,7 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
567 /* Hang up the tools, close up shop, head home */ 567 /* Hang up the tools, close up shop, head home */
568 close(tbInfo.tarFd); 568 close(tbInfo.tarFd);
569 if (errorFlag) 569 if (errorFlag)
570 error_msg("Error exit delayed from previous errors"); 570 bb_error_msg("Error exit delayed from previous errors");
571 571
572 freeHardLinkInfo(&tbInfo.hlInfoHead); 572 freeHardLinkInfo(&tbInfo.hlInfoHead);
573 573
@@ -585,10 +585,9 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
585#ifdef CONFIG_FEATURE_TAR_EXCLUDE 585#ifdef CONFIG_FEATURE_TAR_EXCLUDE
586static llist_t *append_file_list_to_list(const char *filename, llist_t *list) 586static llist_t *append_file_list_to_list(const char *filename, llist_t *list)
587{ 587{
588 FILE *src_stream = xfopen(filename, "r"); 588 FILE *src_stream = bb_xfopen(filename, "r");
589 char *line; 589 char *line;
590 while((line = get_line_from_file(src_stream)) != NULL) { 590 while((line = bb_get_chomped_line_from_file(src_stream)) != NULL) {
591 chomp(line);
592 list = llist_add_to(list, line); 591 list = llist_add_to(list, line);
593 } 592 }
594 fclose(src_stream); 593 fclose(src_stream);
@@ -611,7 +610,7 @@ int tar_main(int argc, char **argv)
611 unsigned char ctx_flag = 0; 610 unsigned char ctx_flag = 0;
612 611
613 if (argc < 2) { 612 if (argc < 2) {
614 show_usage(); 613 bb_show_usage();
615 } 614 }
616 615
617 /* Prepend '-' to the first argument if required */ 616 /* Prepend '-' to the first argument if required */
@@ -690,13 +689,13 @@ int tar_main(int argc, char **argv)
690 break; 689 break;
691#endif 690#endif
692 default: 691 default:
693 show_usage(); 692 bb_show_usage();
694 } 693 }
695 } 694 }
696 695
697 /* Check one and only one context option was given */ 696 /* Check one and only one context option was given */
698 if ((ctx_flag != CTX_CREATE) && (ctx_flag != CTX_TEST) && (ctx_flag != CTX_EXTRACT)) { 697 if ((ctx_flag != CTX_CREATE) && (ctx_flag != CTX_TEST) && (ctx_flag != CTX_EXTRACT)) {
699 show_usage(); 698 bb_show_usage();
700 } 699 }
701 700
702 /* Check if we are reading from stdin */ 701 /* Check if we are reading from stdin */
@@ -740,11 +739,11 @@ int tar_main(int argc, char **argv)
740 tar_handle->src_fd = fileno(stdin); 739 tar_handle->src_fd = fileno(stdin);
741 tar_handle->seek = seek_by_char; 740 tar_handle->seek = seek_by_char;
742 } else { 741 } else {
743 tar_handle->src_fd = xopen(tar_filename, O_RDONLY); 742 tar_handle->src_fd = bb_xopen(tar_filename, O_RDONLY);
744 } 743 }
745 744
746 if ((base_dir) && (chdir(base_dir))) { 745 if ((base_dir) && (chdir(base_dir))) {
747 perror_msg_and_die("Couldnt chdir"); 746 bb_perror_msg_and_die("Couldnt chdir");
748 } 747 }
749 748
750 while (get_header_ptr(tar_handle) == EXIT_SUCCESS); 749 while (get_header_ptr(tar_handle) == EXIT_SUCCESS);
@@ -753,7 +752,7 @@ int tar_main(int argc, char **argv)
753 while (tar_handle->accept) { 752 while (tar_handle->accept) {
754 if (find_list_entry(tar_handle->reject, tar_handle->accept->data) == NULL) { 753 if (find_list_entry(tar_handle->reject, tar_handle->accept->data) == NULL) {
755 if (find_list_entry(tar_handle->passed, tar_handle->accept->data) == NULL) { 754 if (find_list_entry(tar_handle->passed, tar_handle->accept->data) == NULL) {
756 error_msg_and_die("%s: Not found in archive\n", tar_handle->accept->data); 755 bb_error_msg_and_die("%s: Not found in archive\n", tar_handle->accept->data);
757 } 756 }
758 } 757 }
759 tar_handle->accept = tar_handle->accept->link; 758 tar_handle->accept = tar_handle->accept->link;