mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
Add mkdtemp command.
This commit is contained in:
30
daemon/dir.c
30
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;
|
||||
}
|
||||
|
||||
@@ -2442,6 +2442,28 @@ containing C<dir>.
|
||||
It is an interface to the L<scrub(1)> 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<template> parameter should be a full pathname for the
|
||||
temporary directory with the six characters being
|
||||
\"XXXXXX\".
|
||||
|
||||
For example: \"/tmp/tmpXXXXXX\" or \"/Temp/tmpXXXXXX\",
|
||||
the second one being suitable for Windows.
|
||||
|
||||
The name of the temporary directory that was created
|
||||
is returned.
|
||||
|
||||
The caller is responsible for deleting the temporary
|
||||
directory and its contents after use.
|
||||
|
||||
See also: L<mkdtemp(3)>");
|
||||
|
||||
]
|
||||
|
||||
let all_functions = non_daemon_functions @ daemon_functions
|
||||
|
||||
Reference in New Issue
Block a user