Changeset 900 in MondoRescue for trunk/mondo/src/common/libmondo-string.c
- Timestamp:
- Oct 24, 2006, 8:49:18 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/src/common/libmondo-string.c
r863 r900 15 15 #include "libmondo-tools-EXT.h" 16 16 #include <math.h> 17 #include "mr_mem.h" 17 18 18 19 /*@unused@*/ … … 42 43 assert(partno >= 0); 43 44 44 asprintf(&partition, "%s", drive);45 mr_asprintf(&partition, "%s", drive); 45 46 p = partition; 46 47 /* is this a devfs device path? */ … … 55 56 p = partition; 56 57 #ifdef BSD 57 asprintf(&partition, "%ss", p);58 mr_asprintf(&partition, "%ss", p); 58 59 #else 59 60 /* format /dev/cciss/c0d0 */ 60 asprintf(&partition, "%sp", p);61 mr_asprintf(&partition, "%sp", p); 61 62 #endif 62 paranoid_free(p);63 mr_free(p); 63 64 } 64 65 } 65 66 p = partition; 66 asprintf(&partition, "%s%d", p, partno);67 paranoid_free(p);67 mr_asprintf(&partition, "%s%d", p, partno); 68 mr_free(p); 68 69 return (partition); 69 70 } … … 92 93 } 93 94 for (p = in_out; *p == ' '; p++); 94 asprintf(&scratch, p);95 mr_asprintf(&scratch, p); 95 96 strip_spaces (scratch); 96 97 len = (int) strlen(scratch); … … 101 102 } 102 103 in_out[i] = '\0'; 103 asprintf(&out, "%s%s", in_out, scratch);104 paranoid_free(scratch);104 mr_asprintf(&out, "%s%s", in_out, scratch); 105 mr_free(scratch); 105 106 in_out = out; 106 107 for (i = x + len ; i < width - 1; i++) { … … 120 121 bool end = FALSE; 121 122 122 asprintf(&sav, sin);123 mr_asprintf(&sav, sin); 123 124 p = sav; 124 125 while ((*p != '\0') && (! end)) { … … 129 130 // build the new string by recursion 130 131 turn_wildcard_chars_into_literal_chars(q,p); 131 asprintf(&sout, "%s\\%c%s", sav, r, q);132 paranoid_free(q);133 paranoid_free(sav);132 mr_asprintf(&sout, "%s\\%c%s", sav, r, q); 133 mr_free(q); 134 mr_free(sav); 134 135 end = TRUE; 135 136 } … … 160 161 assert(disklist != NULL); 161 162 162 asprintf(&output, "%-24s %8d", disklist->el[lino].device,163 mr_asprintf(&output, "%-24s %8d", disklist->el[lino].device, 163 164 disklist->el[lino].index); 164 165 return (output); … … 188 189 fatal_error("Please use integers only. No decimal points."); 189 190 } 190 asprintf(&tmp, "%s", incoming);191 mr_asprintf(&tmp, "%s", incoming); 191 192 i = (int) strlen(tmp); 192 193 if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') { … … 197 198 tmp[i] = '\0'; 198 199 outval = atol(tmp); 199 paranoid_free(tmp);200 mr_free(tmp); 200 201 201 202 if (ch == 'g' || ch == 'G') { … … 214 215 fatal_error("Integer overflow."); 215 216 } else if (ch != 'm' && ch != 'M') { 216 asprintf(&tmp, "Re: parameter '%s' - bad multiplier ('%c')",217 mr_asprintf(&tmp, "Re: parameter '%s' - bad multiplier ('%c')", 217 218 incoming, ch); 218 219 fatal_error(tmp); … … 240 241 assert(width > 2); 241 242 242 asprintf(&output, "%s", incoming);243 mr_asprintf(&output, "%s", incoming); 243 244 for (i = (int) strlen(output); i < width; i++) { 244 245 output[i] = ' '; … … 268 269 switch (marker) { 269 270 case BLK_START_OF_BACKUP: 270 asprintf(&outstr, "%s", "BLK_START_OF_BACKUP");271 mr_asprintf(&outstr, "%s", "BLK_START_OF_BACKUP"); 271 272 break; 272 273 case BLK_START_OF_TAPE: 273 asprintf(&outstr, "%s", "BLK_START_OF_TAPE");274 mr_asprintf(&outstr, "%s", "BLK_START_OF_TAPE"); 274 275 break; 275 276 case BLK_START_AN_AFIO_OR_SLICE: 276 asprintf(&outstr, "%s", "BLK_START_AN_AFIO_OR_SLICE");277 mr_asprintf(&outstr, "%s", "BLK_START_AN_AFIO_OR_SLICE"); 277 278 break; 278 279 case BLK_STOP_AN_AFIO_OR_SLICE: 279 asprintf(&outstr, "%s", "BLK_STOP_AN_AFIO_OR_SLICE");280 mr_asprintf(&outstr, "%s", "BLK_STOP_AN_AFIO_OR_SLICE"); 280 281 break; 281 282 case BLK_START_AFIOBALLS: 282 asprintf(&outstr, "%s", "BLK_START_AFIOBALLS");283 mr_asprintf(&outstr, "%s", "BLK_START_AFIOBALLS"); 283 284 break; 284 285 case BLK_STOP_AFIOBALLS: 285 asprintf(&outstr, "%s", "BLK_STOP_AFIOBALLS");286 mr_asprintf(&outstr, "%s", "BLK_STOP_AFIOBALLS"); 286 287 break; 287 288 case BLK_STOP_BIGGIEFILES: 288 asprintf(&outstr, "%s", "BLK_STOP_BIGGIEFILES");289 mr_asprintf(&outstr, "%s", "BLK_STOP_BIGGIEFILES"); 289 290 break; 290 291 case BLK_START_A_NORMBIGGIE: 291 asprintf(&outstr, "%s", "BLK_START_A_NORMBIGGIE");292 mr_asprintf(&outstr, "%s", "BLK_START_A_NORMBIGGIE"); 292 293 break; 293 294 case BLK_START_A_PIHBIGGIE: 294 asprintf(&outstr, "%s", "BLK_START_A_PIHBIGGIE");295 mr_asprintf(&outstr, "%s", "BLK_START_A_PIHBIGGIE"); 295 296 break; 296 297 case BLK_START_EXTENDED_ATTRIBUTES: 297 asprintf(&outstr, "%s", "BLK_START_EXTENDED_ATTRIBUTES");298 mr_asprintf(&outstr, "%s", "BLK_START_EXTENDED_ATTRIBUTES"); 298 299 break; 299 300 case BLK_STOP_EXTENDED_ATTRIBUTES: 300 asprintf(&outstr, "%s", "BLK_STOP_EXTENDED_ATTRIBUTES");301 mr_asprintf(&outstr, "%s", "BLK_STOP_EXTENDED_ATTRIBUTES"); 301 302 break; 302 303 case BLK_START_EXAT_FILE: 303 asprintf(&outstr, "%s", "BLK_START_EXAT_FILE");304 mr_asprintf(&outstr, "%s", "BLK_START_EXAT_FILE"); 304 305 break; 305 306 case BLK_STOP_EXAT_FILE: 306 asprintf(&outstr, "%s", "BLK_STOP_EXAT_FILE");307 mr_asprintf(&outstr, "%s", "BLK_STOP_EXAT_FILE"); 307 308 break; 308 309 case BLK_START_BIGGIEFILES: 309 asprintf(&outstr, "%s", "BLK_START_BIGGIEFILES");310 mr_asprintf(&outstr, "%s", "BLK_START_BIGGIEFILES"); 310 311 break; 311 312 case BLK_STOP_A_BIGGIE: 312 asprintf(&outstr, "%s", "BLK_STOP_A_BIGGIE");313 mr_asprintf(&outstr, "%s", "BLK_STOP_A_BIGGIE"); 313 314 break; 314 315 case BLK_END_OF_TAPE: 315 asprintf(&outstr, "%s", "BLK_END_OF_TAPE");316 mr_asprintf(&outstr, "%s", "BLK_END_OF_TAPE"); 316 317 break; 317 318 case BLK_END_OF_BACKUP: 318 asprintf(&outstr, "%s", "BLK_END_OF_BACKUP");319 mr_asprintf(&outstr, "%s", "BLK_END_OF_BACKUP"); 319 320 break; 320 321 case BLK_ABORTED_BACKUP: 321 asprintf(&outstr, "%s", "BLK_ABORTED_BACKUP");322 mr_asprintf(&outstr, "%s", "BLK_ABORTED_BACKUP"); 322 323 break; 323 324 case BLK_START_FILE: 324 asprintf(&outstr, "%s", "BLK_START_FILE");325 mr_asprintf(&outstr, "%s", "BLK_START_FILE"); 325 326 break; 326 327 case BLK_STOP_FILE: 327 asprintf(&outstr, "%s", "BLK_STOP_FILE");328 mr_asprintf(&outstr, "%s", "BLK_STOP_FILE"); 328 329 break; 329 330 default: 330 asprintf(&outstr, "%s (%d)", "BLK_UNKNOWN", marker);331 mr_asprintf(&outstr, "%s (%d)", "BLK_UNKNOWN", marker); 331 332 break; 332 333 } … … 355 356 assert(mountlist != NULL); 356 357 357 asprintf(&output, "%-24s %-24s %-10s %8lld",358 mr_asprintf(&output, "%-24s %-24s %-10s %8lld", 358 359 mountlist->el[lino].device, mountlist->el[lino].mountpoint, 359 360 mountlist->el[lino].format, mountlist->el[lino].size / 1024); … … 386 387 p = ' '; 387 388 } 388 asprintf(&output, "%d %s disk%c ", noof_disks, label, p);389 mr_asprintf(&output, "%d %s disk%c ", noof_disks, label, p); 389 390 /* BERLIOS: replaced with space^^^^ here ! 390 391 while (strlen(output) < 14) { … … 413 414 switch (i) { 414 415 case 0: 415 asprintf(&output, "%s", "zero");416 mr_asprintf(&output, "%s", "zero"); 416 417 break; 417 418 case 1: 418 asprintf(&output, "%s", "one");419 mr_asprintf(&output, "%s", "one"); 419 420 break; 420 421 case 2: 421 asprintf(&output, "%s", "two");422 mr_asprintf(&output, "%s", "two"); 422 423 break; 423 424 case 3: 424 asprintf(&output, "%s", "three");425 mr_asprintf(&output, "%s", "three"); 425 426 break; 426 427 case 4: 427 asprintf(&output, "%s", "four");428 mr_asprintf(&output, "%s", "four"); 428 429 break; 429 430 case 5: 430 asprintf(&output, "%s", "five");431 mr_asprintf(&output, "%s", "five"); 431 432 break; 432 433 case 6: 433 asprintf(&output, "%s", "six");434 mr_asprintf(&output, "%s", "six"); 434 435 break; 435 436 case 7: 436 asprintf(&output, "%s", "seven");437 mr_asprintf(&output, "%s", "seven"); 437 438 break; 438 439 case 8: 439 asprintf(&output, "%s", "eight");440 mr_asprintf(&output, "%s", "eight"); 440 441 break; 441 442 case 9: 442 asprintf(&output, "%s", "nine");443 mr_asprintf(&output, "%s", "nine"); 443 444 case 10: 444 asprintf(&output, "%s", "ten");445 mr_asprintf(&output, "%s", "ten"); 445 446 default: 446 asprintf(&output, "%d", i);447 mr_asprintf(&output, "%d", i); 447 448 } 448 449 return (output); … … 470 471 471 472 strcpy(output, ip); /* just in case the token doesn't appear in string at all */ 472 asprintf(&input, "%s", ip);473 mr_asprintf(&input, "%s", ip); 473 474 while (strstr(input, token)) { 474 475 strcpy(output, input); … … 478 479 p = strstr(input, token) + strlen(token); 479 480 strcat(output, p); 480 paranoid_free(input);481 asprintf(&input, "%s", output);482 } 483 paranoid_free(input);481 mr_free(input); 482 mr_asprintf(&input, "%s", output); 483 } 484 mr_free(input); 484 485 } 485 486 … … 512 513 513 514 if (s != NULL) { 514 asprintf(&suffix, ".%s", s);515 mr_asprintf(&suffix, ".%s", s); 515 516 } else { 516 asprintf(&suffix, "%s", "");517 } 518 asprintf(&output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno,517 mr_asprintf(&suffix, "%s", ""); 518 } 519 mr_asprintf(&output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, 519 520 sliceno, suffix); 520 paranoid_free(suffix);521 mr_free(suffix); 521 522 return (output); 522 523 } … … 578 579 } 579 580 if (strlen(flaws_str) > 0) { 580 asprintf(&flaws_str_A, "%s", flaws_str + 1);581 mr_asprintf(&flaws_str_A, "%s", flaws_str + 1); 581 582 } 582 583 if (strlen(flaws_str_A) >= 74) { 583 584 for (i = 74; flaws_str_A[i] != ' '; i--); 584 asprintf(&flaws_str_B, "%s", flaws_str_A + i + 1);585 mr_asprintf(&flaws_str_B, "%s", flaws_str_A + i + 1); 585 586 flaws_str_A[i] = '\0'; 586 587 } 587 588 if (strlen(flaws_str_B) >= 74) { 588 589 for (i = 74; flaws_str_B[i] != ' '; i--); 589 asprintf(&flaws_str_C, "%s", flaws_str_B + i + 1);590 mr_asprintf(&flaws_str_C, "%s", flaws_str_B + i + 1); 590 591 flaws_str_B[i] = '\0'; 591 592 } … … 669 670 670 671 assert(input != NULL); 671 asprintf(&output, "%s", input);672 mr_asprintf(&output, "%s", input); 672 673 p = strchr(input, '\"'); 673 674 if (p) { 674 675 q = strchr(++p, '\"'); 675 676 if (q) { 676 paranoid_free(output);677 asprintf(&output, "%s", p);677 mr_free(output); 678 mr_asprintf(&output, "%s", p); 678 679 *(strchr(output, '\"')) = '\0'; 679 680 } … … 706 707 original_incoming_length = (int) strlen(in_out); 707 708 for (i = 0; in_out[i] <= ' ' && i < (int) strlen(in_out); i++); 708 asprintf(&tmp, "%s", in_out + i);709 mr_asprintf(&tmp, "%s", in_out + i); 709 710 for (i = (int) strlen(tmp); i > 0 && tmp[i - 1] <= 32; i--); 710 711 tmp[i] = '\0'; … … 724 725 in_out[i++] = ' '; 725 726 } else if (in_out[i] == '\r') { 726 asprintf(&tmp1, "%s", in_out + i);727 mr_asprintf(&tmp1, "%s", in_out + i); 727 728 strcpy(in_out, tmp1); 728 paranoid_free(tmp1);729 mr_free(tmp1); 729 730 i = -1; 730 731 continue; … … 741 742 } 742 743 in_out[i] = '\0'; 743 paranoid_free(tmp);744 mr_free(tmp); 744 745 } 745 746 … … 760 761 761 762 if (incoming[0] == '\"' && incoming[strlen(incoming) - 1] == '\"') { 762 asprintf(&outgoing, "%s", incoming + 1);763 mr_asprintf(&outgoing, "%s", incoming + 1); 763 764 outgoing[strlen(outgoing) - 1] = '\0'; 764 765 } else { 765 asprintf(&outgoing, incoming);766 mr_asprintf(&outgoing, incoming); 766 767 } 767 768 return (outgoing); … … 831 832 832 833 if (raid_level >= 0) { 833 asprintf(&output, " RAID %-2d ", raid_level);834 mr_asprintf(&output, " RAID %-2d ", raid_level); 834 835 } else { 835 asprintf(&output, "Linear RAID");836 mr_asprintf(&output, "Linear RAID"); 836 837 } 837 838 return (output); … … 855 856 assert_string_is_neither_NULL_nor_zerolength(fn); 856 857 if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) { 857 asprintf(&filename, "%s", fn + strlen(MNT_RESTORING));858 mr_asprintf(&filename, "%s", fn + strlen(MNT_RESTORING)); 858 859 } else if (fn[0] != '/') { 859 asprintf(&filename, "/%s", fn);860 mr_asprintf(&filename, "/%s", fn); 860 861 } else { 861 asprintf(&filename, "%s", fn);862 mr_asprintf(&filename, "%s", fn); 862 863 } 863 864 864 865 if (!strncmp(filename, "/var/", 5)) { 865 866 sev = 2; 866 asprintf(&reason,867 mr_asprintf(&reason, 867 868 _("/var's contents will change regularly, inevitably.")); 868 869 } 869 870 if (!strncmp(filename, "/home", 5)) { 870 871 sev = 2; 871 asprintf(&reason,872 mr_asprintf(&reason, 872 873 _("It's in your /home partiton. Therefore, it is important.")); 873 874 } 874 875 if (!strncmp(filename, "/usr/", 5)) { 875 876 sev = 3; 876 asprintf(&reason,877 mr_asprintf(&reason, 877 878 _("You may have installed/removed software during the backup.")); 878 879 } 879 880 if (!strncmp(filename, "/etc/", 5)) { 880 881 sev = 3; 881 asprintf(&reason,882 mr_asprintf(&reason, 882 883 _("Do not edit config files while backing up your PC.")); 883 884 } … … 885 886 || !strcmp(filename, "/etc/mtab")) { 886 887 sev = 1; 887 asprintf(&reason, _("This file changes all the time. It's OK."));888 mr_asprintf(&reason, _("This file changes all the time. It's OK.")); 888 889 } 889 890 if (!strncmp(filename, "/root/", 6)) { 890 891 sev = 3; 891 asprintf(&reason,892 mr_asprintf(&reason, 892 893 _("Were you compiling/editing something in /root?")); 893 894 } 894 895 if (!strncmp(filename, "/root/.", 7)) { 895 896 sev = 2; 896 asprintf(&reason, _("Temp or 'dot' files changed in /root."));897 mr_asprintf(&reason, _("Temp or 'dot' files changed in /root.")); 897 898 } 898 899 if (!strncmp(filename, "/var/lib/", 9)) { 899 900 sev = 2; 900 asprintf(&reason, _("Did you add/remove software during backing?"));901 mr_asprintf(&reason, _("Did you add/remove software during backing?")); 901 902 } 902 903 if (!strncmp(filename, "/var/lib/rpm", 12)) { 903 904 sev = 3; 904 asprintf(&reason, _("Did you add/remove software during backing?"));905 mr_asprintf(&reason, _("Did you add/remove software during backing?")); 905 906 } 906 907 if (!strncmp(filename, "/var/lib/slocate", 16)) { 907 908 sev = 1; 908 asprintf(&reason,909 mr_asprintf(&reason, 909 910 _("The 'update' daemon ran during backup. This does not affect the integrity of your backup.")); 910 911 } … … 913 914 || !strcmp(filename + strlen(filename) - 4, ".log")) { 914 915 sev = 1; 915 asprintf(&reason,916 mr_asprintf(&reason, 916 917 _("Log files change frequently as the computer runs. Fret not.")); 917 918 } 918 919 if (!strncmp(filename, "/var/spool", 10)) { 919 920 sev = 1; 920 asprintf(&reason,921 mr_asprintf(&reason, 921 922 _("Background processes or printers were active. This does not affect the integrity of your backup.")); 922 923 } 923 924 if (!strncmp(filename, "/var/spool/mail", 10)) { 924 925 sev = 2; 925 asprintf(&reason, _("Mail was sent/received during backup."));926 mr_asprintf(&reason, _("Mail was sent/received during backup.")); 926 927 } 927 928 if (filename[strlen(filename) - 1] == '~') { 928 929 sev = 1; 929 asprintf(&reason,930 mr_asprintf(&reason, 930 931 _("Backup copy of another file which was modified recently.")); 931 932 } 932 933 if (strstr(filename, "cache")) { 933 934 sev = 1; 934 asprintf(&reason,935 mr_asprintf(&reason, 935 936 _("Part of a cache of data. Caches change from time to time. Don't worry.")); 936 937 } … … 940 941 || strstr(filename, "/.Xauthority")) { 941 942 sev = 1; 942 asprintf(&reason,943 mr_asprintf(&reason, 943 944 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."); 944 945 } 945 paranoid_free(filename);946 mr_free(filename); 946 947 947 948 if (sev == 0) { 948 949 sev = 3; 949 asprintf(&reason,950 mr_asprintf(&reason, 950 951 _("Changed since backup. Consider running a differential backup in a day or two.")); 951 952 } … … 1005 1006 1006 1007 if (bkpinfo->media_size[g_current_media_number] <= 0) { 1007 asprintf(&outstr, _("Volume %d: %'lld kilobytes archived so far"),1008 mr_asprintf(&outstr, _("Volume %d: %'lld kilobytes archived so far"), 1008 1009 g_current_media_number, g_tape_posK); 1009 1010 … … 1016 1017 (int) (g_tape_posK / 10 / 1017 1018 bkpinfo->media_size[g_current_media_number]); 1018 asprintf(&prepstr, _("Volume %d: ["), g_current_media_number);1019 mr_asprintf(&prepstr, _("Volume %d: ["), g_current_media_number); 1019 1020 } else { 1020 1021 percentage = 1021 1022 (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / 1022 1023 bkpinfo->media_size[g_current_media_number]); 1023 asprintf(&prepstr, "%s %d: [",1024 mr_asprintf(&prepstr, "%s %d: [", 1024 1025 bkpinfo->backup_media_string, 1025 1026 g_current_media_number); … … 1046 1047 /* 1047 1048 log_it("percentage: %d", percentage); 1048 asprintf(&outstr, "%s%s%s] %3d%% used", prepstr, tmp1, tmp2, percentage);1049 mr_asprintf(&outstr, "%s%s%s] %3d%% used", prepstr, tmp1, tmp2, percentage); 1049 1050 */ 1050 asprintf(&outstr, _("%s%s%s] %3d percent used"), prepstr, tmp1, tmp2,1051 mr_asprintf(&outstr, _("%s%s%s] %3d percent used"), prepstr, tmp1, tmp2, 1051 1052 percentage); 1052 paranoid_free(prepstr);1053 paranoid_free(tmp1);1054 paranoid_free(tmp2);1053 mr_free(prepstr); 1054 mr_free(tmp1); 1055 mr_free(tmp2); 1055 1056 return (outstr); 1056 1057 }
Note:
See TracChangeset
for help on using the changeset viewer.