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

r3327@localhost: bruno | 2009-08-04 00:17:46 +0200
popup_and_get_string and build_partition_name now return an allocated string

File:
1 edited

Legend:

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

    r2315 r2316  
    3434 * @param drive The drive basename of the partition name (e.g. /dev/hda)
    3535 * @param partno The partition number (e.g. 1)
    36  * @param partition Where to put the partition name (e.g. /dev/hda1)
    3736 * @return @p partition.
    3837 * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno.
    3938 */
    40 char *build_partition_name(char *partition, const char *drive, int partno)
    41 {
    42     char *p, *c;
    43 
    44     assert(partition != NULL);
     39char *build_partition_name(const char *drive, int partno)
     40{
     41    char *c = NULL;
     42    char *partition = NULL;
     43
    4544    assert_string_is_neither_NULL_nor_zerolength(drive);
    4645    assert(partno >= 0);
    4746
    48     p = strcpy(partition, drive);
     47    mr_asprintf(&partition, drive);
    4948    /* is this a devfs device path? */
    5049    c = strrchr(partition, '/');
    5150    if (c && strncmp(c, "/disc", 5) == 0) {
    5251        /* yup it's devfs, return the "part" path */
     52        /* This strcpy is safe */
    5353        strcpy(c + 1, "part");
    54         p = c + 5;
    5554    } else {
    56         p += strlen(p);
    57         if (isdigit(p[-1])) {
    58             *p++ =
     55        if (isdigit(partition[-1])) {
     56            mr_strcat(partition,
    5957#ifdef BSD
    60                 's';
     58                's');
    6159#else
    62                 'p';
     60                'p');
    6361#endif
    6462        }
    6563    }
    66     sprintf(p, "%d", partno);
    67     return (partition);
    68 }
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
     64    mr_strcat(partition, "%d", partno);
     65    return(partition);
     66}
    8067
    8168
Note: See TracChangeset for help on using the changeset viewer.