Ignore:
Timestamp:
Sep 25, 2013, 9:03:25 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • revert r3188 & r3189 as I started to work on branch 3.0 before deciding it was much better to do it in 3.2. This will allow some small maintenance work on 3.0 if needed, while pushing all the rest to 3.2 and providing early access to it.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/common/libmondo-string.c

    r3188 r3192  
    5151    if (c && strncmp(c, "/disc", 5) == 0) {
    5252        /* yup it's devfs, return the "part" path */
    53         /* This strcpy is safe */
    5453        strcpy(c + 1, "part");
    5554        p = c + 5;
     
    6665    }
    6766    sprintf(p, "%d", partno);
    68     return(partition);
    69 }
     67    return (partition);
     68}
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
    7080
    7181
     
    108118
    109119
     120
     121
     122inline 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
    110136/**
    111137 * Add commas every third place in @p input.
     
    129155        tmp[j - 6] = ',';
    130156        strcpy(tmp + j - 5, pos_w_commas + j - 6);
     157//      tmp[j-2] = ',';
     158//      strcpy(tmp+j-1, pos_w_commas+j-3);
    131159        strcpy(pos_w_commas, tmp);
    132160    }
     
    142170    return (output);
    143171}
     172
     173
     174
     175
     176
     177
     178
    144179
    145180
     
    182217    long outval;
    183218    int i;
    184     char *tmp = NULL;
     219    char *tmp;
    185220    char ch;
    186221
     
    193228        fatal_error("Please use integers only. No decimal points.");
    194229    }
    195 
    196     mr_asprintf(tmp, "%s", incoming);
     230    malloc_string(tmp);
     231    strcpy(tmp, incoming);
    197232    i = (int) strlen(tmp);
    198233    if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') {
     
    203238    tmp[i] = '\0';
    204239    outval = atol(tmp);
    205     mr_free(tmp);
    206 
    207240    if (ch == 'g' || ch == 'G') {
    208241        outval = outval * 1024;
     
    220253        fatal_error("Integer overflow.");
    221254    } 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);
    223257        fatal_error(tmp);
    224258    }
     259    paranoid_free(tmp);
    225260    return (outval);
    226261}
     
    481516
    482517    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);
    483521    assert(value != NULL);
    484522
     
    519557    /*@ buffers **************************************************** */
    520558    static char output[MAX_STR_LEN];
    521     char *suffix = NULL;
     559    static char suffix[MAX_STR_LEN];
    522560
    523561    /*@ end vars *************************************************** */
     
    525563    assert_string_is_neither_NULL_nor_zerolength(path);
    526564    if (s[0] != '\0') {
    527         mr_asprintf(suffix, ".%s", s);
     565        sprintf(suffix, ".%s", s);
    528566    } 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);
    533571    return (output);
    534572}
     
    608646    numA = atol(stringA + start_of_numbers_in_A);
    609647    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     */
    610652    return ((int) (numA - numB));
    611653}
     
    733775    in_out[i] = '\0';
    734776    paranoid_free(tmp);
     777/*  for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */
    735778}
    736779
     
    866909 * @return The severity (1-3).
    867910 */
    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?
     911int 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?
    875920    assert_string_is_neither_NULL_nor_zerolength(fn);
    876921    if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
    877         mr_asprintf(filename, "%s", fn + strlen(MNT_RESTORING));
     922        strcpy(filename, fn + strlen(MNT_RESTORING));
    878923    } else if (fn[0] != '/') {
    879         mr_asprintf(filename, "/%s", fn);
     924        sprintf(filename, "/%s", fn);
    880925    } 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.");
    886932    if (!strncmp(filename, "/var/", 5)) {
    887933        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.");
    890936    }
    891937    if (!strncmp(filename, "/home", 5)) {
    892938        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.");
    895941    }
    896942    if (!strncmp(filename, "/usr/", 5)) {
    897943        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.");
    900946    }
    901947    if (!strncmp(filename, "/etc/", 5)) {
    902948        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.");
    905951    }
    906952    if (!strcmp(filename, "/etc/adjtime")
    907953        || !strcmp(filename, "/etc/mtab")) {
    908954        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.");
    911956    }
    912957    if (!strncmp(filename, "/root/", 6)) {
    913958        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?");
    916960    }
    917961    if (!strncmp(filename, "/root/.", 7)) {
    918962        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.");
    921964    }
    922965    if (!strncmp(filename, "/var/lib/", 9)) {
    923966        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?");
    926968    }
    927969    if (!strncmp(filename, "/var/lib/rpm", 12)) {
    928970        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?");
    931972    }
    932973    if (!strncmp(filename, "/var/lib/slocate", 16)) {
    933974        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.");
    936977    }
    937978    if (!strncmp(filename, "/var/log/", 9)
     
    939980        || !strcmp(filename + strlen(filename) - 4, ".log")) {
    940981        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.");
    943984    }
    944985    if (!strncmp(filename, "/var/spool", 10)) {
    945986        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.");
    948989    }
    949990    if (!strncmp(filename, "/var/spool/mail", 10)) {
    950991        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.");
    953993    }
    954994    if (filename[strlen(filename) - 1] == '~') {
    955995        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.");
    958998    }
    959999    if (strstr(filename, "cache")) {
    9601000        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.");
    9631003    }
    9641004    if (!strncmp(filename, "/var/run/", 9)
     
    9671007        || strstr(filename, "/.Xauthority")) {
    9681008        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.");
    9711011    }
    9721012    if (out_reason) {
    9731013        strcpy(out_reason, reason);
    9741014    }
    975     mr_free(filename);
    976     mr_free(reason);
     1015    paranoid_free(filename);
     1016    paranoid_free(reason);
    9771017    return (sev);
    9781018}
     
    10241064    /*@ buffers ******************************************* */
    10251065    static char outstr[MAX_STR_LEN];
    1026     char *pos_w_commas = NULL;
     1066    char *pos_w_commas, *tmp;
    10271067    char *mds = NULL;
    1028     char *tmp = NULL;
    10291068
    10301069    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);
    10381082        return (outstr);
    10391083    }
    10401084
    1041     /* update screen */
     1085/* update screen */
    10421086    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    10431087        percentage = (int) (g_tape_posK / 10 / bkpinfo->media_size);
     
    10471091        sprintf(outstr, "Volume %d: [", g_current_media_number);
    10481092    } 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);
    10501095        mds = media_descriptor_string(bkpinfo->backup_media_type);
    10511096        sprintf(outstr, "%s %d: [", mds, g_current_media_number);
     
    10601105    j = (int) strlen(outstr);
    10611106    sprintf(outstr + j, "] %d%% used", percentage);
     1107    paranoid_free(pos_w_commas);
     1108    paranoid_free(tmp);
    10621109    return (outstr);
    10631110}
Note: See TracChangeset for help on using the changeset viewer.