]> git.ipfire.org Git - thirdparty/git.git/commitdiff
wrapper: simplify xmkstemp()
authorRené Scharfe <l.s.r@web.de>
Mon, 17 Nov 2025 19:42:55 +0000 (20:42 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Nov 2025 21:53:09 +0000 (13:53 -0800)
Call xmkstemp_mode() instead of duplicating its error handling code.
This switches the implementation from the system's mkstemp(3) to our own
git_mkstemp_mode(), which works just as well.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
wrapper.c

index 2f00d2ac876c16b4addf96ec2ba14dcc90795748..bfe7e30f0c80e8bb1143e65042cd4a9f778b8efe 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -421,24 +421,7 @@ FILE *fopen_or_warn(const char *path, const char *mode)
 
 int xmkstemp(char *filename_template)
 {
-       int fd;
-       char origtemplate[PATH_MAX];
-       strlcpy(origtemplate, filename_template, sizeof(origtemplate));
-
-       fd = mkstemp(filename_template);
-       if (fd < 0) {
-               int saved_errno = errno;
-               const char *nonrelative_template;
-
-               if (strlen(filename_template) != strlen(origtemplate))
-                       filename_template = origtemplate;
-
-               nonrelative_template = absolute_path(filename_template);
-               errno = saved_errno;
-               die_errno("Unable to create temporary file '%s'",
-                       nonrelative_template);
-       }
-       return fd;
+       return xmkstemp_mode(filename_template, 0600);
 }
 
 /* Adapted from libiberty's mkstemp.c. */