scc

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

commit d681ea0ce2e1903f5047140fb3bcb6da1dc0e673
parent 6c5c5ab6a9adc01a81abbc1cc6e2b26d0b9a53fb
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Tue, 12 May 2026 12:15:06 +0200

libc/stdio: Fix tmpnam()

The logic to find the digits to increment was wrong and
it returned FALSE always.

Diffstat:
Msrc/libc/stdio/tmpnam.c | 14++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/libc/stdio/tmpnam.c b/src/libc/stdio/tmpnam.c @@ -11,18 +11,20 @@ char * tmpnam(char *s) { static char tmpl[] = _TMPNAME; - char *p; + char *p, *beg; - for (;;) { - for (p = tmpl; *p && *p != '9'; ++p) + + for (beg = tmpl; *beg < '0' || *beg > '9'; ++beg) + ; + + do { + for (p = beg; *p == '9'; *p++ = '0') ; if (*p == '\0') return NULL; ++*p; + } while (_access(tmpl, F_OK) == 0); - if (_access(tmpl, F_OK) != 0) - break; - } if (s) strcpy(s, tmpl); return tmpl;