Changeset 2357 in MondoRescue for branches/2.2.10/mondo/src/common/libmondo-files.c
- Timestamp:
- Aug 29, 2009, 3:22:10 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-files.c
r2341 r2357 46 46 { 47 47 /*@ buffers ***************************************************** */ 48 static char output[MAX_STR_LEN];48 char *output = NULL; 49 49 char *command = NULL; 50 50 51 51 /*@ pointers **************************************************** */ 52 char *p ;52 char *p = NULL; 53 53 FILE *fin; 54 55 /*@ initialize pointers ***************************************** */56 57 p = output;58 54 59 55 /*@************************************************************** */ … … 64 60 fin = popen(command, "r"); 65 61 if (fin) { 66 (void) fgets(output, MAX_STR_LEN, fin);62 mr_getline(output, fin); 67 63 p = strchr(output, ' '); 64 if (p != NULL) { 65 *p = '\0'; 66 } else { 67 mr_free(output); 68 mr_asprintf(output, ""); 69 } 68 70 paranoid_pclose(fin); 69 71 } … … 71 73 } else { 72 74 log_it("File '%s' not found; cannot calc checksum", filename); 73 } 74 if (p) { 75 *p = '\0'; 75 mr_asprintf(output, ""); 76 76 } 77 77 return (output); … … 125 125 /*@ buffers ***************************************************** */ 126 126 char *command = NULL; 127 char incoming[MAX_STR_LEN];127 char *incoming = NULL; 128 128 129 129 /*@ long ******************************************************** */ … … 132 132 /*@ pointers **************************************************** */ 133 133 FILE *fin; 134 135 /*@ initialize [0] to null ******************************************** */136 incoming[0] = '\0';137 134 138 135 assert_string_is_neither_NULL_nor_zerolength(filename); … … 152 149 noof_lines = 0; 153 150 } else { 154 (void) fgets(incoming, MAX_STR_LEN - 1, fin); 155 while (strlen(incoming) > 0 156 && incoming[strlen(incoming) - 1] < 32) { 151 mr_getline(incoming, fin); 152 while (strlen(incoming) > 0 && incoming[strlen(incoming) - 1] < 32) { 157 153 incoming[strlen(incoming) - 1] = '\0'; 158 154 } 159 155 noof_lines = atol(incoming); 156 mr_free(incoming); 160 157 } 161 158 paranoid_pclose(fin); … … 206 203 char *outfname = NULL; 207 204 char *tmp = NULL; 208 char incoming[MAX_STR_LEN];205 char *incoming = NULL; 209 206 210 207 /*@ int ********************************************************* */ … … 236 233 mr_free(outfname); 237 234 238 for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin); 239 fgets(incoming, MAX_STR_LEN, fin)) { 235 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 240 236 i = strlen(incoming) - 1; 241 237 if (i >= 0 && incoming[i] < 32) { … … 247 243 log_it("Excluding '%s'-nonexistent\n", incoming); 248 244 } 249 } 245 mr_free(incoming); 246 } 247 mr_free(incoming); 248 250 249 paranoid_fclose(fout); 251 250 paranoid_fclose(fin); … … 470 469 { 471 470 /*@ buffers ***************************************************** */ 472 static char output[MAX_STR_LEN];471 char *output = NULL; 473 472 char *command = NULL; 474 473 … … 480 479 if (!does_file_exist(filename)) { 481 480 log_it("Tring to get last line of nonexistent file (%s)", filename); 482 output[0] = '\0';481 mr_asprintf(output, ""); 483 482 return (output); 484 483 } … … 487 486 mr_free(command); 488 487 489 (void) fgets(output, MAX_STR_LEN, fin);488 mr_getline(output, fin); 490 489 paranoid_pclose(fin); 491 490 while (strlen(output) > 0 && output[strlen(output) - 1] < 32) { … … 526 525 * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed. 527 526 */ 528 int 529 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) 530 { 527 int make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) { 531 528 /*@ pointers **************************************************** */ 532 529 FILE *fin; … … 539 536 540 537 /*@ buffer ****************************************************** */ 541 char stub_fname[1000];542 char curr_fname[1000];538 char *stub_fname = NULL; 539 char *curr_fname = NULL; 543 540 char *curr_cksum = NULL; 544 541 char *tmp = NULL; … … 571 568 return (1); 572 569 } 573 for (fgets(stub_fname, 999, fin); !feof(fin); 574 fgets(stub_fname, 999, fin)) { 570 for (mr_getline(stub_fname, fin); !feof(fin); mr_getline(stub_fname, fin)) { 575 571 if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) { 576 572 stub_fname[i] = '\0'; 577 573 } 578 574 mr_asprintf(tmp, "%s%s", comppath, stub_fname); 579 strcpy(curr_fname, tmp + 1); 575 mr_free(stub_fname); 576 577 mr_asprintf(curr_fname, "%s", tmp + 1); 580 578 mr_free(tmp); 581 579 … … 587 585 current_time = get_time(); 588 586 counter = 0; 587 /* BERLIOS: 37 really ? */ 589 588 curr_fname[37] = '\0'; 590 589 curr_pos = ftello(fin) / 1024; 591 590 percentage = (int) (curr_pos * 100 / filelist_length); 592 591 time_taken = current_time - start_time; 593 if (percentage == 0) { 594 /* printf("%0d%% done \r",percentage); */ 595 } else { 592 if (percentage != 0) { 596 593 time_remaining = time_taken * 100 / (long) (percentage) - time_taken; 597 594 log_to_screen("%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname); … … 599 596 sync(); 600 597 } 601 } 598 mr_free(curr_fname); 599 } 600 mr_free(stub_fname); 601 602 602 paranoid_fclose(fout); 603 603 paranoid_fclose(fin); … … 678 678 679 679 /*@ buffers **************************************************** */ 680 char incoming[MAX_STR_LEN];680 char *incoming = NULL; 681 681 682 682 /*@ end vars *************************************************** */ … … 689 689 return (0); 690 690 } 691 (void) fgets(incoming, MAX_STR_LEN - 1, fin);691 mr_getline(incoming, fin); 692 692 while (!feof(fin)) { 693 693 if (strstr(incoming, wildcard)) { 694 694 matches++; 695 695 } 696 (void) fgets(incoming, MAX_STR_LEN - 1, fin); 697 } 696 mr_free(incoming); 697 mr_getline(incoming, fin); 698 } 699 mr_free(incoming); 698 700 paranoid_fclose(fin); 699 701 return (matches); … … 737 739 { 738 740 /*@ buffers ***************************************************** */ 739 char *fname ;741 char *fname = NULL; 740 742 char *biggielist = NULL; 741 743 char *tmp = NULL; … … 751 753 /*@ end vars *************************************************** */ 752 754 753 malloc_string(fname);754 755 log_it("Calculating size of all biggiefiles (in total)"); 755 756 mr_asprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); … … 762 763 } else { 763 764 log_msg(4, "Reading it..."); 764 for (fgets(fname, MAX_STR_LEN, fin); !feof(fin); 765 fgets(fname, MAX_STR_LEN, fin)) { 765 for (mr_getline(fname, fin); !feof(fin); mr_getline(fname, fin)) { 766 766 if (fname[strlen(fname) - 1] <= 32) { 767 767 fname[strlen(fname) - 1] = '\0'; … … 772 772 if (!tmp) { 773 773 mr_free(tmp); 774 mr_free(fname); 774 775 fatal_error("ntfsresize not found"); 775 776 } … … 799 800 break; 800 801 } 801 } 802 mr_free(fname); 803 } 804 mr_free(fname); 802 805 } 803 806 log_it("Closing..."); 804 807 paranoid_fclose(fin); 805 808 log_it("Finished calculating total size of all biggiefiles"); 806 paranoid_free(fname);807 809 return (scratchL); 808 810 } … … 817 819 { 818 820 /*@ buffer ****************************************************** */ 819 char tmp[MAX_STR_LEN];821 char *tmp = NULL; 820 822 char *command = NULL; 821 823 long long llres; … … 833 835 llres = 0; 834 836 } else { 835 (void) fgets(tmp, MAX_STR_LEN, fin);837 mr_getline(tmp, fin); 836 838 paranoid_pclose(fin); 837 839 p = strchr(tmp, '\t'); … … 843 845 llres += (int) (*p - '0'); 844 846 } 847 mr_free(tmp); 845 848 } 846 849 mr_free(command); … … 1289 1292 } 1290 1293 /* BERLIOS: This is just plain WRONG !! */ 1291 mr_asprintf(do_not_compress_these, "%s", last_line_of_file(tmp));1294 do_not_compress_these = last_line_of_file(tmp); 1292 1295 mr_free(tmp); 1293 1296
Note:
See TracChangeset
for help on using the changeset viewer.