shithub: scc

Download patch

ref: 27e13dac39adc371f8bdf5f36e3bb3962aaea004
parent: ea588fa8a7848ccd7a048251823d72559574f6a8
parent: fcec548cff5349d73e1c64a99aee77ce2331858d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jun 1 10:19:01 EDT 2022

Merge remote-tracking branch 'origin/master'

--- a/include/bits/darwin/sys/stdio.h
+++ b/include/bits/darwin/sys/stdio.h
@@ -3,6 +3,5 @@
 #define FOPEN_MAX 16
 
 #define TMP_MAX 25
-#define L_tmpnam 256
-
 #define _TMPNAME "/tmp/tmp.0000000"
+#define L_tmpnam sizeof(_TMPNAME)
--- a/include/bits/dragonfly/sys/stdio.h
+++ b/include/bits/dragonfly/sys/stdio.h
@@ -3,6 +3,5 @@
 #define FOPEN_MAX 16
 
 #define TMP_MAX 25
-#define L_tmpnam 256
-
 #define _TMPNAME "/tmp/tmp.0000000"
+#define L_tmpnam sizeof(_TMPNAME)
--- a/include/bits/linux/sys/stdio.h
+++ b/include/bits/linux/sys/stdio.h
@@ -3,6 +3,5 @@
 #define FOPEN_MAX 16
 
 #define TMP_MAX 25
-#define L_tmpnam 256
-
 #define _TMPNAME "/tmp/tmp.0000000"
+#define L_tmpnam sizeof(_TMPNAME)
--- a/include/bits/netbsd/sys/stdio.h
+++ b/include/bits/netbsd/sys/stdio.h
@@ -3,6 +3,5 @@
 #define FOPEN_MAX 16
 
 #define TMP_MAX 25
-#define L_tmpnam 256
-
 #define _TMPNAME "/tmp/tmp.0000000"
+#define L_tmpnam sizeof(_TMPNAME)
--- a/include/bits/openbsd/sys/stdio.h
+++ b/include/bits/openbsd/sys/stdio.h
@@ -3,6 +3,5 @@
 #define FOPEN_MAX 16
 
 #define TMP_MAX 25
-#define L_tmpnam 256
-
 #define _TMPNAME "/tmp/tmp.0000000"
+#define L_tmpnam sizeof(_TMPNAME)
--- a/src/libc/stdio/tmpnam.c
+++ b/src/libc/stdio/tmpnam.c
@@ -10,16 +10,9 @@
 char *
 tmpnam(char *s)
 {
-	static char *tmpl, buf[L_tmpnam];
+	static char tmpl[] = _TMPNAME;
 	char *p;
 
-	if (*buf == '\0') {
-		for (tmpl = buf, p = _TMPNAME; *tmpl++ = *p++; )
-			;
-		for (p = tmpl; p < &buf[L_tmpnam-1]; ++p)
-			*p = '0';
-		*p = '\0';
-	}
 	for (;;) {
 		for (p = tmpl; *p && *p != '9'; ++p)
 			;
@@ -27,10 +20,10 @@
 			return NULL;
 		++*p;
 
-		if (_access(buf, F_OK) != 0)
+		if (_access(tmpl, F_OK) != 0)
 			break;
 	}
 	if (s)
-		strcpy(s, buf);
-	return buf;
+		strcpy(s, tmpl);
+	return tmpl;
 }