Ignore:
Timestamp:
May 6, 2014, 10:24:14 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • change function number_of_disks_as_string into one returning a dynamically allocates tring
File:
1 edited

Legend:

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

    r3288 r3289  
    381381 * there will be a weird double space in the middle, so pass *something*.
    382382 * @return The string containing "X blah blah disk(s)".
    383  * @note The returned string points to static storage and will be overwritten with each call.
     383 * @note The returned string is dynamically allocated and should be freed by caller
    384384 */
    385385char *number_of_disks_as_string(int noof_disks, char *label)
    386386{
    387387
    388     /*@ buffers ********************************************************* */
    389     static char output[MAX_STR_LEN];
    390 
    391     /*@ char     ******************************************************** */
    392     char p;
    393 
    394     assert(label != NULL);
    395 
    396     if (noof_disks > 1) {
    397         p = 's';
    398     } else {
    399         p = ' ';
    400     }
    401     sprintf(output, "%d %s disk%c", noof_disks, label, p);
    402     while (strlen(output) < 14) {
    403         strcat(output, " ");
    404     }
    405     return (output);
     388/*@ buffers ********************************************************* */
     389char *output = NULL;
     390
     391/*@ char     ******************************************************** */
     392char p;
     393
     394assert(label != NULL);
     395
     396if (noof_disks > 1) {
     397    p = 's';
     398} else {
     399    p = ' ';
     400}
     401mr_asprintf(output, "%d %s disk%c", noof_disks, label, p);
     402/* Useful ??
     403while (strlen(output) < 14) {
     404    strcat(output, " ");
     405}
     406*/
     407return (output);
    406408}
    407409
Note: See TracChangeset for help on using the changeset viewer.