[libvirt] [PATCH 1/8] Add virFileMakeParentPath helper function

Eric Blake eblake at redhat.com
Tue Feb 18 04:07:01 UTC 2014


On 02/17/2014 09:38 AM, Daniel P. Berrange wrote:
> Add a helper function which takes a file path and ensures
> that all directory components leading up to the file exist.
> IOW, it strips the filename part of the path and passes
> the result to virFileMakePath.
> 
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
>  src/libvirt_private.syms |  1 +
>  src/util/virfile.c       | 27 +++++++++++++++++++++++++++
>  src/util/virfile.h       |  1 +
>  3 files changed, 29 insertions(+)


> +int
> +virFileMakeParentPath(const char *path)
> +{
> +    char *p;
> +    char *tmp;
> +    int ret;
> +
> +    VIR_DEBUG("path=%s", path);
> +
> +    if (VIR_STRDUP(tmp, path) < 0) {
> +        errno = ENOMEM;
> +        return -1;
> +    }
> +
> +    if ((p = strrchr(tmp, '/')) == NULL) {
> +        errno = EINVAL;
> +        return -1;

Memleak of tmp.

ACK with that fixed.

-- 
Eric Blake   eblake 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: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140217/0246f2e6/attachment-0001.sig>


More information about the libvir-list mailing list