summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/build-support/libredirect/libredirect.c16
-rw-r--r--pkgs/build-support/libredirect/test.c4
2 files changed, 20 insertions, 0 deletions
diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c
index 07eca43810c..1222d2ee75c 100644
--- a/pkgs/build-support/libredirect/libredirect.c
+++ b/pkgs/build-support/libredirect/libredirect.c
@@ -459,3 +459,19 @@ WRAPPER(char *, mkdtemp)(char *template)
     return template;
 }
 WRAPPER_DEF(mkdtemp)
+
+WRAPPER(char *, mktemp)(char *template)
+{
+    char * (*mktemp_real) (char *template) = LOOKUP_REAL(mktemp);
+    char buf[PATH_MAX];
+    char * rewritten = rewrite_non_const(template, buf);
+    char * retval = mktemp_real(rewritten);
+    if (retval == NULL) {
+        return retval;
+    };
+    if (rewritten != template) {
+        copy_temp_wildcard(template, rewritten, 0);
+    }
+    return template;
+}
+WRAPPER_DEF(mktemp)
diff --git a/pkgs/build-support/libredirect/test.c b/pkgs/build-support/libredirect/test.c
index 012e4aa4b28..144e6d3d66d 100644
--- a/pkgs/build-support/libredirect/test.c
+++ b/pkgs/build-support/libredirect/test.c
@@ -121,6 +121,10 @@ int main(int argc, char *argv[])
     assert(mkdtemp(buf) == buf);
     assert_mktemp_path(TESTDIR "/temp", "", buf);
 
+    strncpy(buf, TESTDIR "/tempXXXXXX", PATH_MAX);
+    assert(mktemp(buf) == buf);
+    assert_mktemp_path(TESTDIR "/temp", "", buf);
+
     test_spawn();
     test_system();