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

Eric Blake eblake at redhat.com
Thu Oct 18 12:52:54 UTC 2012


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 617 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20121018/7e46de53/attachment-0001.sig>


More information about the libvir-list mailing list