libredirect: add support for mkdtemp

This commit is contained in:
Robert Scott 2022-01-16 22:37:37 +00:00
parent 2185a70fa4
commit d38832ace0
2 changed files with 20 additions and 0 deletions

View File

@ -443,3 +443,19 @@ WRAPPER(int, mkostemps)(char *template, int suffixlen, int flags)
return retval;
}
WRAPPER_DEF(mkostemps)
WRAPPER(char *, mkdtemp)(char *template)
{
char * (*mkdtemp_real) (char *template) = LOOKUP_REAL(mkdtemp);
char buf[PATH_MAX];
char * rewritten = rewrite_non_const(template, buf);
char * retval = mkdtemp_real(rewritten);
if (retval == NULL) {
return retval;
};
if (rewritten != template) {
copy_temp_wildcard(template, rewritten, 0);
}
return template;
}
WRAPPER_DEF(mkdtemp)

View File

@ -117,6 +117,10 @@ int main(int argc, char *argv[])
assert_mktemp_path(TESTDIR "/temp", ".test", buf);
close(testfd);
strncpy(buf, TESTDIR "/tempXXXXXX", PATH_MAX);
assert(mkdtemp(buf) == buf);
assert_mktemp_path(TESTDIR "/temp", "", buf);
test_spawn();
test_system();