Ignore:
Timestamp:
Aug 18, 2009, 2:29:11 PM (11 years ago)
Author:
Bruno Cornec
Message:

r3324@localhost: bruno | 2009-07-31 23:42:57 +0200
percent_media_full_comment now allocates memory

File:
1 edited

Legend:

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

    r2287 r2313  
    155155        tmp[j - 6] = ',';
    156156        strcpy(tmp + j - 5, pos_w_commas + j - 6);
    157 //      tmp[j-2] = ',';
    158 //      strcpy(tmp+j-1, pos_w_commas+j-3);
    159157        strcpy(pos_w_commas, tmp);
    160158    }
     
    10871085    /*@ int *********************************************** */
    10881086    int percentage;
    1089     int j;
    10901087
    10911088    /*@ buffers ******************************************* */
    1092     static char outstr[MAX_STR_LEN];
     1089    char *outstr = NULL;
    10931090    char *pos_w_commas, *tmp;
    10941091    char *mds = NULL;
    10951092
    10961093    assert(bkpinfo != NULL);
    1097     malloc_string(pos_w_commas);
    1098     malloc_string(tmp);
    1099     sprintf(tmp, "%lld", g_tape_posK);
    1100     strcpy(pos_w_commas, commarize(tmp));
    1101 
    1102 
    1103 
    1104     if (bkpinfo->media_size[g_current_media_number] <= 0)
    1105 //    { fatal_error( "percentage_media_full_comment() - unknown media size"); }
    1106     {
    1107         sprintf(outstr, "Volume %d: %s kilobytes archived so far",
    1108                 g_current_media_number, pos_w_commas);
     1094
     1095    if (bkpinfo->media_size[g_current_media_number] <= 0) {
     1096        malloc_string(pos_w_commas);
     1097        malloc_string(tmp);
     1098        sprintf(tmp, "%lld", g_tape_posK);
     1099        strcpy(pos_w_commas, commarize(tmp));
     1100        paranoid_free(tmp);
     1101        mr_asprintf(&outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
     1102        paranoid_free(pos_w_commas);
    11091103        return (outstr);
    11101104    }
     
    11181112            percentage = 100;
    11191113        }
    1120         sprintf(outstr, "Volume %d: [", g_current_media_number);
     1114        mr_asprintf(&outstr, "Volume %d: [", g_current_media_number);
    11211115    } else {
    11221116        percentage =
     
    11241118                   bkpinfo->media_size[g_current_media_number]);
    11251119        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1126         sprintf(outstr, "%s %d: [", mds, g_current_media_number);
     1120        mr_asprintf(&outstr, "%s %d: [", mds, g_current_media_number);
    11271121        mr_free(mds);
    11281122    }
    11291123    for (j = 0; j < percentage; j += 5) {
    1130         strcat(outstr, "*");
     1124        mr_strcat(outstr, "*");
    11311125    }
    11321126    for (; j < 100; j += 5) {
    1133         strcat(outstr, ".");
    1134     }
    1135     j = (int) strlen(outstr);
    1136     sprintf(outstr + j, "] %d%% used", percentage);
    1137     paranoid_free(pos_w_commas);
    1138     paranoid_free(tmp);
     1127        mr_strcat(outstr, ".");
     1128    }
     1129    mr_strcat(outstr, "] %d%% used", percentage);
    11391130    return (outstr);
    11401131}
Note: See TracChangeset for help on using the changeset viewer.