[libvirt] [PATCH][RFC] helper of copy-storage-* features
li guang
lig.fnst at cn.fujitsu.com
Fri Oct 19 01:36:55 UTC 2012
在 2012-10-18四的 06:52 -0600,Eric Blake写道:
> 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.
>
OK, I'll use mdir_name directly, new patch will come up later.
Thanks!
--
liguang lig.fnst at cn.fujitsu.com
FNST linux kernel team
More information about the libvir-list
mailing list