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

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



On 10/17/2012 08:50 PM, Doug Goldstein wrote:
> On Sun, Oct 14, 2012 at 9:48 PM, liguang <lig fnst cn fujitsu com> 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 redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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