scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 10561bd468a51e001fea28922b18d172d832d72b
parent fb8dbbcf81b73f635d9269048a6a1e09c029c1ed
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 27 May 2022 11:05:20 +0200

libc: Simplify tmpnam()

Tmpnam() was doing a runtime initialization that was not
needed anymore because we can customize _TMPNAME now if
it is needed, because we have its definition in a system
specific header.

Diffstat:
Minclude/bits/darwin/sys/stdio.h | 3+--
Minclude/bits/dragonfly/sys/stdio.h | 3+--
Minclude/bits/linux/sys/stdio.h | 3+--
Minclude/bits/netbsd/sys/stdio.h | 3+--
Minclude/bits/openbsd/sys/stdio.h | 3+--
Msrc/libc/stdio/tmpnam.c | 15++++-----------
6 files changed, 9 insertions(+), 21 deletions(-)

diff --git 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) diff --git 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) diff --git 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) diff --git 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) diff --git 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) diff --git 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 @@ tmpnam(char *s) 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; }