Re: [PATCH][RFC] helper of copy-storage-* features

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/17/2012 08:50 PM, Doug Goldstein wrote:
> On Sun, Oct 14, 2012 at 9:48 PM, liguang <lig.fnst@xxxxxxxxxxxxxx> wrote:
>> help to create disk images copy-storage-* required,
>> try to do non-shared migration without bothering to
>> create disk images at target by hand.
>>

>> +char *virDirOfFile(const char *file)

Poor naming.  Better might be virDirName, to match what we are wrapping.

>> +{
>> +    char *p, *tmp;
>> +
>> +    if (file == NULL)
>> +        return NULL;
>> +    if ((tmp = strdup(file)) == NULL)
>> +        return NULL;
>> +    if ((p = strrchr(file, '/')) == NULL)
>> +        return getcwd(tmp, strlen(file));
>> +    if (strlen(p) == 0)
>> +        return NULL;
>> +    tmp[strlen(file) - strlen(p)] = '\0';
>> +
>> +    return tmp;
>> +}
> 
> Eric probably knows better than I do but it seems like we can probably
> pull in dirname() from gnulib for this rather than implementing our
> own version.

'git grep mdir_name' - we're already using the gnulib interface in two
places.  It does not handle NULL input, but that would imply you just write:

char *
virDirName(const char *file)
{
    if (!file)
        return NULL;
    return mdir_name(file);
}

and let the caller deal with NULL return.  Then again, if the caller is
going to virReportOOMError(), it may be better to just use mdir_name()
directly, and guarantee that the caller doesn't pass in NULL in the
first place.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]