Add mkdtemp command.

This commit is contained in:
Richard W.M. Jones
2009-06-24 18:22:37 +01:00
parent af0cfda7e4
commit 8228eec990
2 changed files with 52 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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