From: Richard W.M. Jones Date: Wed, 24 Jun 2009 17:22:37 +0000 (+0100) Subject: Add mkdtemp command. X-Git-Tag: 1.0.54~38 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=8228eec99045ae720d8ef35851aa8c278f6b4e5c Add mkdtemp command. --- diff --git a/daemon/dir.c b/daemon/dir.c index 83536ef..753323d 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -201,3 +201,33 @@ do_is_dir (char *path) return S_ISDIR (buf.st_mode); } + +char * +do_mkdtemp (char *template) +{ + char *r; + + NEED_ROOT (NULL); + ABS_PATH (template, NULL); + + CHROOT_IN; + r = mkdtemp (template); + CHROOT_OUT; + + if (r == NULL) { + reply_with_perror ("mkdtemp: %s", template); + return NULL; + } + + /* The caller will free template AND try to free the return value, + * so we must make a copy here. + */ + if (r == template) { + r = strdup (template); + if (r == NULL) { + reply_with_perror ("strdup"); + return NULL; + } + } + return r; +} diff --git a/src/generator.ml b/src/generator.ml index 51d3235..e378395 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2442,6 +2442,28 @@ containing C. It is an interface to the L program. See that manual page for more details."); + ("mkdtemp", (RString "dir", [String "template"]), 117, [], + [InitBasicFS, Always, TestRun ( + [["mkdir"; "/tmp"]; + ["mkdtemp"; "/tmp/tmpXXXXXX"]])], + "create a temporary directory", + "\ +This command creates a temporary directory. The +C