aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/tar.c29
-rw-r--r--tar.c29
2 files changed, 34 insertions, 24 deletions
diff --git a/archival/tar.c b/archival/tar.c
index bb66d40cc..018ccdc11 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -501,7 +501,19 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
501} 501}
502#endif //tar_create 502#endif //tar_create
503 503
504void append_file_to_list(char *filename, char ***name_list, int *num_of_entries) 504void append_file_to_list(const char *new_name, char ***list, int *list_count)
505{
506 *list = realloc(*list, sizeof(char *) * (*list_count + 2));
507 if (last_char_is(new_name, '/')) {
508 (*list)[*list_count] = concat_path_file(new_name, "*");
509 } else {
510 (*list)[*list_count] = xstrdup(new_name);
511 }
512 (*list_count)++;
513 (*list)[*list_count] = NULL;
514}
515
516void append_file_list_to_list(char *filename, char ***name_list, int *num_of_entries)
505{ 517{
506 FILE *src_stream; 518 FILE *src_stream;
507 char *line; 519 char *line;
@@ -513,13 +525,10 @@ void append_file_to_list(char *filename, char ***name_list, int *num_of_entries)
513 if (line_ptr) { 525 if (line_ptr) {
514 *line_ptr = '\0'; 526 *line_ptr = '\0';
515 } 527 }
516 *name_list = realloc(*name_list, sizeof(char *) * (*num_of_entries + 2)); 528 append_file_to_list(line, name_list, num_of_entries);
517 (*name_list)[*num_of_entries] = xstrdup(line);
518 (*num_of_entries)++;
519 free(line); 529 free(line);
520 } 530 }
521 fclose(src_stream); 531 fclose(src_stream);
522 (*name_list)[*num_of_entries] = NULL;
523} 532}
524 533
525#ifdef BB_FEATURE_TAR_EXCLUDE 534#ifdef BB_FEATURE_TAR_EXCLUDE
@@ -627,13 +636,12 @@ int tar_main(int argc, char **argv)
627 /* Exclude or Include files listed in <filename>*/ 636 /* Exclude or Include files listed in <filename>*/
628#ifdef BB_FEATURE_TAR_EXCLUDE 637#ifdef BB_FEATURE_TAR_EXCLUDE
629 case 'X': 638 case 'X':
630 append_file_to_list(optarg, &exclude_list, &exclude_list_count); 639 append_file_list_to_list(optarg, &exclude_list, &exclude_list_count);
631 exclude_list[exclude_list_count] = NULL;
632 break; 640 break;
633#endif 641#endif
634 case 'T': 642 case 'T':
635 // by default a list is an include list 643 // by default a list is an include list
636 append_file_to_list(optarg, &include_list, &include_list_count); 644 append_file_list_to_list(optarg, &include_list, &include_list_count);
637 break; 645 break;
638 646
639 case 'C': // Change to dir <optarg> 647 case 'C': // Change to dir <optarg>
@@ -683,11 +691,8 @@ int tar_main(int argc, char **argv)
683 691
684 /* Setup an array of filenames to work with */ 692 /* Setup an array of filenames to work with */
685 while (optind < argc) { 693 while (optind < argc) {
686 include_list = realloc(include_list, sizeof(char *) * (include_list_count + 2)); 694 append_file_to_list(argv[optind], &include_list, &include_list_count);
687 include_list[include_list_count] = xstrdup(argv[optind]);
688 include_list_count++;
689 optind++; 695 optind++;
690 include_list[include_list_count] = NULL;
691 } 696 }
692 697
693 /* By default the include list is the list we act on */ 698 /* By default the include list is the list we act on */
diff --git a/tar.c b/tar.c
index bb66d40cc..018ccdc11 100644
--- a/tar.c
+++ b/tar.c
@@ -501,7 +501,19 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
501} 501}
502#endif //tar_create 502#endif //tar_create
503 503
504void append_file_to_list(char *filename, char ***name_list, int *num_of_entries) 504void append_file_to_list(const char *new_name, char ***list, int *list_count)
505{
506 *list = realloc(*list, sizeof(char *) * (*list_count + 2));
507 if (last_char_is(new_name, '/')) {
508 (*list)[*list_count] = concat_path_file(new_name, "*");
509 } else {
510 (*list)[*list_count] = xstrdup(new_name);
511 }
512 (*list_count)++;
513 (*list)[*list_count] = NULL;
514}
515
516void append_file_list_to_list(char *filename, char ***name_list, int *num_of_entries)
505{ 517{
506 FILE *src_stream; 518 FILE *src_stream;
507 char *line; 519 char *line;
@@ -513,13 +525,10 @@ void append_file_to_list(char *filename, char ***name_list, int *num_of_entries)
513 if (line_ptr) { 525 if (line_ptr) {
514 *line_ptr = '\0'; 526 *line_ptr = '\0';
515 } 527 }
516 *name_list = realloc(*name_list, sizeof(char *) * (*num_of_entries + 2)); 528 append_file_to_list(line, name_list, num_of_entries);
517 (*name_list)[*num_of_entries] = xstrdup(line);
518 (*num_of_entries)++;
519 free(line); 529 free(line);
520 } 530 }
521 fclose(src_stream); 531 fclose(src_stream);
522 (*name_list)[*num_of_entries] = NULL;
523} 532}
524 533
525#ifdef BB_FEATURE_TAR_EXCLUDE 534#ifdef BB_FEATURE_TAR_EXCLUDE
@@ -627,13 +636,12 @@ int tar_main(int argc, char **argv)
627 /* Exclude or Include files listed in <filename>*/ 636 /* Exclude or Include files listed in <filename>*/
628#ifdef BB_FEATURE_TAR_EXCLUDE 637#ifdef BB_FEATURE_TAR_EXCLUDE
629 case 'X': 638 case 'X':
630 append_file_to_list(optarg, &exclude_list, &exclude_list_count); 639 append_file_list_to_list(optarg, &exclude_list, &exclude_list_count);
631 exclude_list[exclude_list_count] = NULL;
632 break; 640 break;
633#endif 641#endif
634 case 'T': 642 case 'T':
635 // by default a list is an include list 643 // by default a list is an include list
636 append_file_to_list(optarg, &include_list, &include_list_count); 644 append_file_list_to_list(optarg, &include_list, &include_list_count);
637 break; 645 break;
638 646
639 case 'C': // Change to dir <optarg> 647 case 'C': // Change to dir <optarg>
@@ -683,11 +691,8 @@ int tar_main(int argc, char **argv)
683 691
684 /* Setup an array of filenames to work with */ 692 /* Setup an array of filenames to work with */
685 while (optind < argc) { 693 while (optind < argc) {
686 include_list = realloc(include_list, sizeof(char *) * (include_list_count + 2)); 694 append_file_to_list(argv[optind], &include_list, &include_list_count);
687 include_list[include_list_count] = xstrdup(argv[optind]);
688 include_list_count++;
689 optind++; 695 optind++;
690 include_list[include_list_count] = NULL;
691 } 696 }
692 697
693 /* By default the include list is the list we act on */ 698 /* By default the include list is the list we act on */