Changeset 900 in MondoRescue for trunk/mondo/src/common/libmondo-string.c


Ignore:
Timestamp:
Oct 24, 2006, 8:49:18 AM (17 years ago)
Author:
Bruno Cornec
Message:

Huge patch to introduce low level functions that will bw used everywhere (mr_free, mr_asprintf, ...)
Nearly linking now due to that.

File:
1 edited

Legend:

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

    r863 r900  
    1515#include "libmondo-tools-EXT.h"
    1616#include <math.h>
     17#include "mr_mem.h"
    1718
    1819/*@unused@*/
     
    4243    assert(partno >= 0);
    4344
    44     asprintf(&partition, "%s", drive);
     45    mr_asprintf(&partition, "%s", drive);
    4546    p = partition;
    4647    /* is this a devfs device path? */
     
    5556            p = partition;
    5657#ifdef BSD
    57             asprintf(&partition, "%ss", p);
     58            mr_asprintf(&partition, "%ss", p);
    5859#else
    5960            /* format /dev/cciss/c0d0 */
    60             asprintf(&partition, "%sp", p);
     61            mr_asprintf(&partition, "%sp", p);
    6162#endif
    62             paranoid_free(p);
     63            mr_free(p);
    6364        }
    6465    }
    6566    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);
    6869    return (partition);
    6970}
     
    9293    }
    9394    for (p = in_out; *p == ' '; p++);
    94     asprintf(&scratch, p);
     95    mr_asprintf(&scratch, p);
    9596    strip_spaces (scratch);
    9697    len = (int) strlen(scratch);
     
    101102    }
    102103    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);
    105106    in_out = out;
    106107    for (i = x + len ; i < width - 1; i++) {
     
    120121    bool end = FALSE;
    121122
    122     asprintf(&sav, sin);
     123    mr_asprintf(&sav, sin);
    123124    p = sav;
    124125    while ((*p != '\0') && (! end)) {
     
    129130                                    // build the new string by recursion
    130131            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);
    134135            end = TRUE;
    135136        }
     
    160161    assert(disklist != NULL);
    161162
    162     asprintf(&output, "%-24s %8d", disklist->el[lino].device,
     163    mr_asprintf(&output, "%-24s %8d", disklist->el[lino].device,
    163164             disklist->el[lino].index);
    164165    return (output);
     
    188189        fatal_error("Please use integers only. No decimal points.");
    189190    }
    190     asprintf(&tmp, "%s", incoming);
     191    mr_asprintf(&tmp, "%s", incoming);
    191192    i = (int) strlen(tmp);
    192193    if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') {
     
    197198    tmp[i] = '\0';
    198199    outval = atol(tmp);
    199     paranoid_free(tmp);
     200    mr_free(tmp);
    200201
    201202    if (ch == 'g' || ch == 'G') {
     
    214215        fatal_error("Integer overflow.");
    215216    } 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')",
    217218                 incoming, ch);
    218219        fatal_error(tmp);
     
    240241    assert(width > 2);
    241242
    242     asprintf(&output, "%s", incoming);
     243    mr_asprintf(&output, "%s", incoming);
    243244    for (i = (int) strlen(output); i < width; i++) {
    244245        output[i] = ' ';
     
    268269    switch (marker) {
    269270    case BLK_START_OF_BACKUP:
    270         asprintf(&outstr, "%s", "BLK_START_OF_BACKUP");
     271        mr_asprintf(&outstr, "%s", "BLK_START_OF_BACKUP");
    271272        break;
    272273    case BLK_START_OF_TAPE:
    273         asprintf(&outstr, "%s", "BLK_START_OF_TAPE");
     274        mr_asprintf(&outstr, "%s", "BLK_START_OF_TAPE");
    274275        break;
    275276    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");
    277278        break;
    278279    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");
    280281        break;
    281282    case BLK_START_AFIOBALLS:
    282         asprintf(&outstr, "%s", "BLK_START_AFIOBALLS");
     283        mr_asprintf(&outstr, "%s", "BLK_START_AFIOBALLS");
    283284        break;
    284285    case BLK_STOP_AFIOBALLS:
    285         asprintf(&outstr, "%s", "BLK_STOP_AFIOBALLS");
     286        mr_asprintf(&outstr, "%s", "BLK_STOP_AFIOBALLS");
    286287        break;
    287288    case BLK_STOP_BIGGIEFILES:
    288         asprintf(&outstr, "%s", "BLK_STOP_BIGGIEFILES");
     289        mr_asprintf(&outstr, "%s", "BLK_STOP_BIGGIEFILES");
    289290        break;
    290291    case BLK_START_A_NORMBIGGIE:
    291         asprintf(&outstr, "%s", "BLK_START_A_NORMBIGGIE");
     292        mr_asprintf(&outstr, "%s", "BLK_START_A_NORMBIGGIE");
    292293        break;
    293294    case BLK_START_A_PIHBIGGIE:
    294         asprintf(&outstr, "%s", "BLK_START_A_PIHBIGGIE");
     295        mr_asprintf(&outstr, "%s", "BLK_START_A_PIHBIGGIE");
    295296        break;
    296297    case BLK_START_EXTENDED_ATTRIBUTES:
    297         asprintf(&outstr, "%s", "BLK_START_EXTENDED_ATTRIBUTES");
     298        mr_asprintf(&outstr, "%s", "BLK_START_EXTENDED_ATTRIBUTES");
    298299        break;
    299300    case BLK_STOP_EXTENDED_ATTRIBUTES:
    300         asprintf(&outstr, "%s", "BLK_STOP_EXTENDED_ATTRIBUTES");
     301        mr_asprintf(&outstr, "%s", "BLK_STOP_EXTENDED_ATTRIBUTES");
    301302        break;
    302303    case BLK_START_EXAT_FILE:
    303         asprintf(&outstr, "%s", "BLK_START_EXAT_FILE");
     304        mr_asprintf(&outstr, "%s", "BLK_START_EXAT_FILE");
    304305        break;
    305306    case BLK_STOP_EXAT_FILE:
    306         asprintf(&outstr, "%s", "BLK_STOP_EXAT_FILE");
     307        mr_asprintf(&outstr, "%s", "BLK_STOP_EXAT_FILE");
    307308        break;
    308309    case BLK_START_BIGGIEFILES:
    309         asprintf(&outstr, "%s", "BLK_START_BIGGIEFILES");
     310        mr_asprintf(&outstr, "%s", "BLK_START_BIGGIEFILES");
    310311        break;
    311312    case BLK_STOP_A_BIGGIE:
    312         asprintf(&outstr, "%s", "BLK_STOP_A_BIGGIE");
     313        mr_asprintf(&outstr, "%s", "BLK_STOP_A_BIGGIE");
    313314        break;
    314315    case BLK_END_OF_TAPE:
    315         asprintf(&outstr, "%s", "BLK_END_OF_TAPE");
     316        mr_asprintf(&outstr, "%s", "BLK_END_OF_TAPE");
    316317        break;
    317318    case BLK_END_OF_BACKUP:
    318         asprintf(&outstr, "%s", "BLK_END_OF_BACKUP");
     319        mr_asprintf(&outstr, "%s", "BLK_END_OF_BACKUP");
    319320        break;
    320321    case BLK_ABORTED_BACKUP:
    321         asprintf(&outstr, "%s", "BLK_ABORTED_BACKUP");
     322        mr_asprintf(&outstr, "%s", "BLK_ABORTED_BACKUP");
    322323        break;
    323324    case BLK_START_FILE:
    324         asprintf(&outstr, "%s", "BLK_START_FILE");
     325        mr_asprintf(&outstr, "%s", "BLK_START_FILE");
    325326        break;
    326327    case BLK_STOP_FILE:
    327         asprintf(&outstr, "%s", "BLK_STOP_FILE");
     328        mr_asprintf(&outstr, "%s", "BLK_STOP_FILE");
    328329        break;
    329330    default:
    330         asprintf(&outstr, "%s (%d)", "BLK_UNKNOWN", marker);
     331        mr_asprintf(&outstr, "%s (%d)", "BLK_UNKNOWN", marker);
    331332        break;
    332333    }
     
    355356    assert(mountlist != NULL);
    356357
    357     asprintf(&output, "%-24s %-24s %-10s %8lld",
     358    mr_asprintf(&output, "%-24s %-24s %-10s %8lld",
    358359             mountlist->el[lino].device, mountlist->el[lino].mountpoint,
    359360             mountlist->el[lino].format, mountlist->el[lino].size / 1024);
     
    386387        p = ' ';
    387388    }
    388     asprintf(&output, "%d %s disk%c    ", noof_disks, label, p);
     389    mr_asprintf(&output, "%d %s disk%c    ", noof_disks, label, p);
    389390    /* BERLIOS: replaced with space^^^^ here !
    390391       while (strlen(output) < 14) {
     
    413414    switch (i) {
    414415    case 0:
    415         asprintf(&output, "%s", "zero");
     416        mr_asprintf(&output, "%s", "zero");
    416417        break;
    417418    case 1:
    418         asprintf(&output, "%s", "one");
     419        mr_asprintf(&output, "%s", "one");
    419420        break;
    420421    case 2:
    421         asprintf(&output, "%s", "two");
     422        mr_asprintf(&output, "%s", "two");
    422423        break;
    423424    case 3:
    424         asprintf(&output, "%s", "three");
     425        mr_asprintf(&output, "%s", "three");
    425426        break;
    426427    case 4:
    427         asprintf(&output, "%s", "four");
     428        mr_asprintf(&output, "%s", "four");
    428429        break;
    429430    case 5:
    430         asprintf(&output, "%s", "five");
     431        mr_asprintf(&output, "%s", "five");
    431432        break;
    432433    case 6:
    433         asprintf(&output, "%s", "six");
     434        mr_asprintf(&output, "%s", "six");
    434435        break;
    435436    case 7:
    436         asprintf(&output, "%s", "seven");
     437        mr_asprintf(&output, "%s", "seven");
    437438        break;
    438439    case 8:
    439         asprintf(&output, "%s", "eight");
     440        mr_asprintf(&output, "%s", "eight");
    440441        break;
    441442    case 9:
    442         asprintf(&output, "%s", "nine");
     443        mr_asprintf(&output, "%s", "nine");
    443444    case 10:
    444         asprintf(&output, "%s", "ten");
     445        mr_asprintf(&output, "%s", "ten");
    445446    default:
    446         asprintf(&output, "%d", i);
     447        mr_asprintf(&output, "%d", i);
    447448    }
    448449    return (output);
     
    470471
    471472    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);
    473474    while (strstr(input, token)) {
    474475        strcpy(output, input);
     
    478479        p = strstr(input, token) + strlen(token);
    479480        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);
    484485}
    485486
     
    512513
    513514    if (s != NULL) {
    514         asprintf(&suffix, ".%s", s);
     515        mr_asprintf(&suffix, ".%s", s);
    515516    } 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,
    519520             sliceno, suffix);
    520     paranoid_free(suffix);
     521    mr_free(suffix);
    521522    return (output);
    522523}
     
    578579    }
    579580    if (strlen(flaws_str) > 0) {
    580         asprintf(&flaws_str_A, "%s", flaws_str + 1);
     581        mr_asprintf(&flaws_str_A, "%s", flaws_str + 1);
    581582    }
    582583    if (strlen(flaws_str_A) >= 74) {
    583584        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);
    585586        flaws_str_A[i] = '\0';
    586587    }
    587588    if (strlen(flaws_str_B) >= 74) {
    588589        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);
    590591        flaws_str_B[i] = '\0';
    591592    }
     
    669670
    670671    assert(input != NULL);
    671     asprintf(&output, "%s", input);
     672    mr_asprintf(&output, "%s", input);
    672673    p = strchr(input, '\"');
    673674    if (p) {
    674675        q = strchr(++p, '\"');
    675676        if (q) {
    676             paranoid_free(output);
    677             asprintf(&output, "%s", p);
     677            mr_free(output);
     678            mr_asprintf(&output, "%s", p);
    678679            *(strchr(output, '\"')) = '\0';
    679680        }
     
    706707    original_incoming_length = (int) strlen(in_out);
    707708    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);
    709710    for (i = (int) strlen(tmp); i > 0 && tmp[i - 1] <= 32; i--);
    710711    tmp[i] = '\0';
     
    724725                in_out[i++] = ' ';
    725726            } else if (in_out[i] == '\r') {
    726                 asprintf(&tmp1, "%s", in_out + i);
     727                mr_asprintf(&tmp1, "%s", in_out + i);
    727728                strcpy(in_out, tmp1);
    728                 paranoid_free(tmp1);
     729                mr_free(tmp1);
    729730                i = -1;
    730731                continue;
     
    741742    }
    742743    in_out[i] = '\0';
    743     paranoid_free(tmp);
     744    mr_free(tmp);
    744745}
    745746
     
    760761
    761762    if (incoming[0] == '\"' && incoming[strlen(incoming) - 1] == '\"') {
    762         asprintf(&outgoing, "%s", incoming + 1);
     763        mr_asprintf(&outgoing, "%s", incoming + 1);
    763764        outgoing[strlen(outgoing) - 1] = '\0';
    764765    } else {
    765         asprintf(&outgoing, incoming);
     766        mr_asprintf(&outgoing, incoming);
    766767    }
    767768    return (outgoing);
     
    831832
    832833    if (raid_level >= 0) {
    833         asprintf(&output, " RAID %-2d ", raid_level);
     834        mr_asprintf(&output, " RAID %-2d ", raid_level);
    834835    } else {
    835         asprintf(&output, "Linear RAID");
     836        mr_asprintf(&output, "Linear RAID");
    836837    }
    837838    return (output);
     
    855856    assert_string_is_neither_NULL_nor_zerolength(fn);
    856857    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));
    858859    } else if (fn[0] != '/') {
    859         asprintf(&filename, "/%s", fn);
     860        mr_asprintf(&filename, "/%s", fn);
    860861    } else {
    861         asprintf(&filename, "%s", fn);
     862        mr_asprintf(&filename, "%s", fn);
    862863    }
    863864
    864865    if (!strncmp(filename, "/var/", 5)) {
    865866        sev = 2;
    866         asprintf(&reason,
     867        mr_asprintf(&reason,
    867868                 _("/var's contents will change regularly, inevitably."));
    868869    }
    869870    if (!strncmp(filename, "/home", 5)) {
    870871        sev = 2;
    871         asprintf(&reason,
     872        mr_asprintf(&reason,
    872873                 _("It's in your /home partiton. Therefore, it is important."));
    873874    }
    874875    if (!strncmp(filename, "/usr/", 5)) {
    875876        sev = 3;
    876         asprintf(&reason,
     877        mr_asprintf(&reason,
    877878                 _("You may have installed/removed software during the backup."));
    878879    }
    879880    if (!strncmp(filename, "/etc/", 5)) {
    880881        sev = 3;
    881         asprintf(&reason,
     882        mr_asprintf(&reason,
    882883                 _("Do not edit config files while backing up your PC."));
    883884    }
     
    885886        || !strcmp(filename, "/etc/mtab")) {
    886887        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."));
    888889    }
    889890    if (!strncmp(filename, "/root/", 6)) {
    890891        sev = 3;
    891         asprintf(&reason,
     892        mr_asprintf(&reason,
    892893                 _("Were you compiling/editing something in /root?"));
    893894    }
    894895    if (!strncmp(filename, "/root/.", 7)) {
    895896        sev = 2;
    896         asprintf(&reason, _("Temp or 'dot' files changed in /root."));
     897        mr_asprintf(&reason, _("Temp or 'dot' files changed in /root."));
    897898    }
    898899    if (!strncmp(filename, "/var/lib/", 9)) {
    899900        sev = 2;
    900         asprintf(&reason, _("Did you add/remove software during backing?"));
     901        mr_asprintf(&reason, _("Did you add/remove software during backing?"));
    901902    }
    902903    if (!strncmp(filename, "/var/lib/rpm", 12)) {
    903904        sev = 3;
    904         asprintf(&reason, _("Did you add/remove software during backing?"));
     905        mr_asprintf(&reason, _("Did you add/remove software during backing?"));
    905906    }
    906907    if (!strncmp(filename, "/var/lib/slocate", 16)) {
    907908        sev = 1;
    908         asprintf(&reason,
     909        mr_asprintf(&reason,
    909910                 _("The 'update' daemon ran during backup. This does not affect the integrity of your backup."));
    910911    }
     
    913914        || !strcmp(filename + strlen(filename) - 4, ".log")) {
    914915        sev = 1;
    915         asprintf(&reason,
     916        mr_asprintf(&reason,
    916917                 _("Log files change frequently as the computer runs. Fret not."));
    917918    }
    918919    if (!strncmp(filename, "/var/spool", 10)) {
    919920        sev = 1;
    920         asprintf(&reason,
     921        mr_asprintf(&reason,
    921922                 _("Background processes or printers were active. This does not affect the integrity of your backup."));
    922923    }
    923924    if (!strncmp(filename, "/var/spool/mail", 10)) {
    924925        sev = 2;
    925         asprintf(&reason, _("Mail was sent/received during backup."));
     926        mr_asprintf(&reason, _("Mail was sent/received during backup."));
    926927    }
    927928    if (filename[strlen(filename) - 1] == '~') {
    928929        sev = 1;
    929         asprintf(&reason,
     930        mr_asprintf(&reason,
    930931                 _("Backup copy of another file which was modified recently."));
    931932    }
    932933    if (strstr(filename, "cache")) {
    933934        sev = 1;
    934         asprintf(&reason,
     935        mr_asprintf(&reason,
    935936                 _("Part of a cache of data. Caches change from time to time. Don't worry."));
    936937    }
     
    940941        || strstr(filename, "/.Xauthority")) {
    941942        sev = 1;
    942         asprintf(&reason,
     943        mr_asprintf(&reason,
    943944                 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");
    944945    }
    945     paranoid_free(filename);
     946    mr_free(filename);
    946947
    947948    if (sev == 0) {
    948949        sev = 3;
    949         asprintf(&reason,
     950        mr_asprintf(&reason,
    950951                 _("Changed since backup. Consider running a differential backup in a day or two."));
    951952    }
     
    10051006
    10061007    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"),
    10081009                 g_current_media_number, g_tape_posK);
    10091010
     
    10161017            (int) (g_tape_posK / 10 /
    10171018                   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);
    10191020    } else {
    10201021        percentage =
    10211022            (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 /
    10221023                   bkpinfo->media_size[g_current_media_number]);
    1023         asprintf(&prepstr, "%s %d: [",
     1024        mr_asprintf(&prepstr, "%s %d: [",
    10241025                 bkpinfo->backup_media_string,
    10251026                 g_current_media_number);
     
    10461047    /*
    10471048       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);
    10491050     */
    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,
    10511052             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);
    10551056    return (outstr);
    10561057}
Note: See TracChangeset for help on using the changeset viewer.