Changeset 3859 in MondoRescue for branches/3.3/mondo/src/common


Ignore:
Timestamp:
Mar 7, 2024, 1:33:54 AM (4 months ago)
Author:
Bruno Cornec
Message:

Fix build_partition_name to allocate dynamically and change proto accordingly

Location:
branches/3.3/mondo/src/common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/mondo/src/common/libmondo-devices.c

    r3857 r3859  
    356356    assert(partno >= 0 && partno < 999);
    357357
    358     malloc_string(searchstr);
    359 
    360358#ifdef __FreeBSD__
    361359    // We assume here that this is running from mondorestore. (It is.)
    362     mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, build_partition_name(tmp, drive, partno));
     360    tmp = build_partition_name(drive, partno);
     361    mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, tmp);
     362    mr_free(tmp);
    363363    res = system(program);
    364364    mr_free(program);
     
    376376    mr_free(program);
    377377
    378     (void) build_partition_name(searchstr, drive, partno);
    379     strcat(searchstr, " ");
     378    searchstr = build_partition_name(drive, partno);
     379    mr_strcat(searchstr, " ");
    380380    for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) {
    381381        if (strstr(incoming, searchstr)) {
     
    384384        mr_free(incoming);
    385385    }
     386    mr_free(searchstr);
    386387    mr_free(incoming);
    387388
     
    389390        log_OS_error("Cannot pclose fin");
    390391    }
    391     paranoid_free(searchstr);
    392392    return (res);
    393393}
  • branches/3.3/mondo/src/common/libmondo-string-EXT.h

    r3858 r3859  
    33 */
    44
    5 extern char *build_partition_name(char *partition, const char *drive,
    6                                   int partno);
     5extern char *build_partition_name(const char *drive, int partno);
    76extern char *commarize(char *);
    87extern char *disklist_entry_to_string(struct list_of_disks *disklist,
  • branches/3.3/mondo/src/common/libmondo-string.c

    r3858 r3859  
    3535 * @param drive The drive basename of the partition name (e.g. /dev/hda)
    3636 * @param partno The partition number (e.g. 1)
    37  * @param partition Where to put the partition name (e.g. /dev/hda1)
    38  * @return @p partition.
     37 * @return @p the partition name (e.g. /dev/hda1)
    3938 * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno.
    4039 */
    41 char *build_partition_name(char *partition, const char *drive, int partno)
     40char *build_partition_name(const char *drive, int partno)
    4241{
    4342    char *p, *c;
    4443
    45     assert(partition != NULL);
    4644    assert_string_is_neither_NULL_nor_zerolength(drive);
    4745    assert(partno >= 0);
    4846
    49     p = strcpy(partition, drive);
     47    mr_free(partition);
     48    mr_asprintf(partition, "%s", drive);
     49    p = partition;
    5050    /* is this a devfs device path? */
    5151    c = strrchr(partition, '/');
     
    5454        /* This strcpy is safe */
    5555        strcpy(c + 1, "part");
    56         p = c + 5;
    5756    } else {
    5857        p += strlen(p);
    5958        if (isdigit(p[-1])) {
    60             *p++ =
     59            mr_strcat(partition, "%c",
    6160#ifdef BSD
    6261                's';
     
    6463                'p';
    6564#endif
     65                );
    6666        }
    6767    }
    68     sprintf(p, "%d", partno);
     68    mr_strcat(partition, "%d", partno);
    6969    return(partition);
    7070}
  • branches/3.3/mondo/src/common/libmondo-string.h

    r3858 r3859  
    33 */
    44
    5 char *build_partition_name(char *partition, const char *drive, int partno);
    65char *commarize(char *);
    76char *disklist_entry_to_string(struct list_of_disks *disklist, int lino);
Note: See TracChangeset for help on using the changeset viewer.