Changeset 3192 in MondoRescue for branches/3.0/mondo/src/common/libmondo-string.c
- Timestamp:
- Sep 25, 2013, 9:03:25 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/mondo/src/common/libmondo-string.c
r3188 r3192 51 51 if (c && strncmp(c, "/disc", 5) == 0) { 52 52 /* yup it's devfs, return the "part" path */ 53 /* This strcpy is safe */54 53 strcpy(c + 1, "part"); 55 54 p = c + 5; … … 66 65 } 67 66 sprintf(p, "%d", partno); 68 return(partition); 69 } 67 return (partition); 68 } 69 70 71 72 73 74 75 76 77 78 79 70 80 71 81 … … 108 118 109 119 120 121 122 inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin) 123 { 124 char *p, *q; 125 126 for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) { 127 if (strchr("[]*?", *p)) { 128 *(q++) = '\\'; 129 } 130 } 131 *q = *p; // for the final '\0' 132 } 133 134 135 110 136 /** 111 137 * Add commas every third place in @p input. … … 129 155 tmp[j - 6] = ','; 130 156 strcpy(tmp + j - 5, pos_w_commas + j - 6); 157 // tmp[j-2] = ','; 158 // strcpy(tmp+j-1, pos_w_commas+j-3); 131 159 strcpy(pos_w_commas, tmp); 132 160 } … … 142 170 return (output); 143 171 } 172 173 174 175 176 177 178 144 179 145 180 … … 182 217 long outval; 183 218 int i; 184 char *tmp = NULL;219 char *tmp; 185 220 char ch; 186 221 … … 193 228 fatal_error("Please use integers only. No decimal points."); 194 229 } 195 196 mr_asprintf(tmp, "%s", incoming);230 malloc_string(tmp); 231 strcpy(tmp, incoming); 197 232 i = (int) strlen(tmp); 198 233 if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') { … … 203 238 tmp[i] = '\0'; 204 239 outval = atol(tmp); 205 mr_free(tmp);206 207 240 if (ch == 'g' || ch == 'G') { 208 241 outval = outval * 1024; … … 220 253 fatal_error("Integer overflow."); 221 254 } else if (ch != 'm' && ch != 'M') { 222 mr_asprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", incoming, ch); 255 sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", 256 incoming, ch); 223 257 fatal_error(tmp); 224 258 } 259 paranoid_free(tmp); 225 260 return (outval); 226 261 } … … 481 516 482 517 input = malloc(2000); 518 // BERLIOS: seems to cause invalid errors 519 //assert_string_is_neither_NULL_nor_zerolength(ip); 520 assert_string_is_neither_NULL_nor_zerolength(token); 483 521 assert(value != NULL); 484 522 … … 519 557 /*@ buffers **************************************************** */ 520 558 static char output[MAX_STR_LEN]; 521 char *suffix = NULL;559 static char suffix[MAX_STR_LEN]; 522 560 523 561 /*@ end vars *************************************************** */ … … 525 563 assert_string_is_neither_NULL_nor_zerolength(path); 526 564 if (s[0] != '\0') { 527 mr_asprintf(suffix, ".%s", s);565 sprintf(suffix, ".%s", s); 528 566 } else { 529 mr_asprintf(suffix, "");530 } 531 sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, suffix);532 mr_free(suffix);567 suffix[0] = '\0'; 568 } 569 sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, 570 suffix); 533 571 return (output); 534 572 } … … 608 646 numA = atol(stringA + start_of_numbers_in_A); 609 647 numB = atol(stringB + start_of_numbers_in_B); 648 /* 649 sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB); 650 log_to_screen(tmp); 651 */ 610 652 return ((int) (numA - numB)); 611 653 } … … 733 775 in_out[i] = '\0'; 734 776 paranoid_free(tmp); 777 /* for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */ 735 778 } 736 779 … … 866 909 * @return The severity (1-3). 867 910 */ 868 int severity_of_difference(char *fn, char *out_reason) { 869 870 int sev = 3; 871 char *reason = NULL; 872 char *filename = NULL; 873 874 // out_reason might be null on purpose, so don't bomb if it is :) OK? 911 int severity_of_difference(char *fn, char *out_reason) 912 { 913 int sev; 914 char *reason; 915 char *filename; 916 917 malloc_string(reason); 918 malloc_string(filename); 919 // out_reason might be null on purpose, so don't bomb if it is :) OK? 875 920 assert_string_is_neither_NULL_nor_zerolength(fn); 876 921 if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) { 877 mr_asprintf(filename, "%s", fn + strlen(MNT_RESTORING));922 strcpy(filename, fn + strlen(MNT_RESTORING)); 878 923 } else if (fn[0] != '/') { 879 mr_asprintf(filename, "/%s", fn);924 sprintf(filename, "/%s", fn); 880 925 } else { 881 mr_asprintf(filename, "%s", fn); 882 } 883 884 mr_asprintf(reason, "Changed since backup. Consider running a differential backup in a day or two."); 885 926 strcpy(filename, fn); 927 } 928 929 sev = 3; 930 sprintf(reason, 931 "Changed since backup. Consider running a differential backup in a day or two."); 886 932 if (!strncmp(filename, "/var/", 5)) { 887 933 sev = 2; 888 mr_free(reason);889 mr_asprintf(reason,"/var's contents will change regularly, inevitably.");934 sprintf(reason, 935 "/var's contents will change regularly, inevitably."); 890 936 } 891 937 if (!strncmp(filename, "/home", 5)) { 892 938 sev = 2; 893 mr_free(reason);894 mr_asprintf(reason,"It's in your /home directory. Therefore, it is important.");939 sprintf(reason, 940 "It's in your /home directory. Therefore, it is important."); 895 941 } 896 942 if (!strncmp(filename, "/usr/", 5)) { 897 943 sev = 3; 898 mr_free(reason);899 mr_asprintf(reason,"You may have installed/removed software during the backup.");944 sprintf(reason, 945 "You may have installed/removed software during the backup."); 900 946 } 901 947 if (!strncmp(filename, "/etc/", 5)) { 902 948 sev = 3; 903 mr_free(reason);904 mr_asprintf(reason,"Do not edit config files while backing up your PC.");949 sprintf(reason, 950 "Do not edit config files while backing up your PC."); 905 951 } 906 952 if (!strcmp(filename, "/etc/adjtime") 907 953 || !strcmp(filename, "/etc/mtab")) { 908 954 sev = 1; 909 mr_free(reason); 910 mr_asprintf(reason, "This file changes all the time. It's OK."); 955 sprintf(reason, "This file changes all the time. It's OK."); 911 956 } 912 957 if (!strncmp(filename, "/root/", 6)) { 913 958 sev = 3; 914 mr_free(reason); 915 mr_asprintf(reason, "Were you compiling/editing something in /root?"); 959 sprintf(reason, "Were you compiling/editing something in /root?"); 916 960 } 917 961 if (!strncmp(filename, "/root/.", 7)) { 918 962 sev = 2; 919 mr_free(reason); 920 mr_asprintf(reason, "Temp or 'dot' files changed in /root."); 963 sprintf(reason, "Temp or 'dot' files changed in /root."); 921 964 } 922 965 if (!strncmp(filename, "/var/lib/", 9)) { 923 966 sev = 2; 924 mr_free(reason); 925 mr_asprintf(reason, "Did you add/remove software during backing?"); 967 sprintf(reason, "Did you add/remove software during backing?"); 926 968 } 927 969 if (!strncmp(filename, "/var/lib/rpm", 12)) { 928 970 sev = 3; 929 mr_free(reason); 930 mr_asprintf(reason, "Did you add/remove software during backing?"); 971 sprintf(reason, "Did you add/remove software during backing?"); 931 972 } 932 973 if (!strncmp(filename, "/var/lib/slocate", 16)) { 933 974 sev = 1; 934 mr_free(reason);935 mr_asprintf(reason,"The 'update' daemon ran during backup. This does not affect the integrity of your backup.");975 sprintf(reason, 976 "The 'update' daemon ran during backup. This does not affect the integrity of your backup."); 936 977 } 937 978 if (!strncmp(filename, "/var/log/", 9) … … 939 980 || !strcmp(filename + strlen(filename) - 4, ".log")) { 940 981 sev = 1; 941 mr_free(reason);942 mr_asprintf(reason,"Log files change frequently as the computer runs. Fret not.");982 sprintf(reason, 983 "Log files change frequently as the computer runs. Fret not."); 943 984 } 944 985 if (!strncmp(filename, "/var/spool", 10)) { 945 986 sev = 1; 946 mr_free(reason);947 mr_asprintf(reason,"Background processes or printers were active. This does not affect the integrity of your backup.");987 sprintf(reason, 988 "Background processes or printers were active. This does not affect the integrity of your backup."); 948 989 } 949 990 if (!strncmp(filename, "/var/spool/mail", 10)) { 950 991 sev = 2; 951 mr_free(reason); 952 mr_asprintf(reason, "Mail was sent/received during backup."); 992 sprintf(reason, "Mail was sent/received during backup."); 953 993 } 954 994 if (filename[strlen(filename) - 1] == '~') { 955 995 sev = 1; 956 mr_free(reason);957 mr_asprintf(reason,"Backup copy of another file which was modified recently.");996 sprintf(reason, 997 "Backup copy of another file which was modified recently."); 958 998 } 959 999 if (strstr(filename, "cache")) { 960 1000 sev = 1; 961 mr_free(reason);962 mr_asprintf(reason,"Part of a cache of data. Caches change from time to time. Don't worry.");1001 sprintf(reason, 1002 "Part of a cache of data. Caches change from time to time. Don't worry."); 963 1003 } 964 1004 if (!strncmp(filename, "/var/run/", 9) … … 967 1007 || strstr(filename, "/.Xauthority")) { 968 1008 sev = 1; 969 mr_free(reason);970 mr_asprintf(reason,"Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");1009 sprintf(reason, 1010 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."); 971 1011 } 972 1012 if (out_reason) { 973 1013 strcpy(out_reason, reason); 974 1014 } 975 mr_free(filename);976 mr_free(reason);1015 paranoid_free(filename); 1016 paranoid_free(reason); 977 1017 return (sev); 978 1018 } … … 1024 1064 /*@ buffers ******************************************* */ 1025 1065 static char outstr[MAX_STR_LEN]; 1026 char *pos_w_commas = NULL;1066 char *pos_w_commas, *tmp; 1027 1067 char *mds = NULL; 1028 char *tmp = NULL;1029 1068 1030 1069 assert(bkpinfo != NULL); 1031 1032 if (bkpinfo->media_size <= 0) { 1033 mr_asprintf(tmp, "%lld", g_tape_posK); 1034 mr_asprintf(pos_w_commas, "%s", commarize(tmp)); 1035 mr_free(tmp); 1036 sprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas); 1037 mr_free(pos_w_commas); 1070 malloc_string(pos_w_commas); 1071 malloc_string(tmp); 1072 sprintf(tmp, "%lld", g_tape_posK); 1073 strcpy(pos_w_commas, commarize(tmp)); 1074 1075 1076 1077 if (bkpinfo->media_size <= 0) 1078 // { fatal_error( "percentage_media_full_comment() - unknown media size"); } 1079 { 1080 sprintf(outstr, "Volume %d: %s kilobytes archived so far", 1081 g_current_media_number, pos_w_commas); 1038 1082 return (outstr); 1039 1083 } 1040 1084 1041 1085 /* update screen */ 1042 1086 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1043 1087 percentage = (int) (g_tape_posK / 10 / bkpinfo->media_size); … … 1047 1091 sprintf(outstr, "Volume %d: [", g_current_media_number); 1048 1092 } else { 1049 percentage = (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size); 1093 percentage = 1094 (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size); 1050 1095 mds = media_descriptor_string(bkpinfo->backup_media_type); 1051 1096 sprintf(outstr, "%s %d: [", mds, g_current_media_number); … … 1060 1105 j = (int) strlen(outstr); 1061 1106 sprintf(outstr + j, "] %d%% used", percentage); 1107 paranoid_free(pos_w_commas); 1108 paranoid_free(tmp); 1062 1109 return (outstr); 1063 1110 }
Note:
See TracChangeset
for help on using the changeset viewer.