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(a)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