scc

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

tmpnam.c (481B)


      1 #include <stdio.h>
      2 #include <string.h>
      3 
      4 #include "../syscall.h"
      5 
      6 #undef tmpnam
      7 
      8 char *
      9 tmpnam(char *s)
     10 {
     11 	static char *tmpl, buf[L_tmpnam];
     12 	char *p;
     13 
     14 	if (*buf == '\0') {
     15 		for (tmpl = buf, p = _TMPNAME; *tmpl++ = *p++; )
     16 			;
     17 		for (p = tmpl; p < &buf[L_tmpnam-1]; ++p)
     18 			*p = '0';
     19 		*p = '\0';
     20 	}
     21 	for (;;) {
     22 		for (p = tmpl; *p && *p != '9'; ++p)
     23 			;
     24 		if (*p == '\0')
     25 			return NULL;
     26 		++*p;
     27 		if (_access(buf, 0) != 0)
     28 			break;
     29 	}
     30 	if (s)
     31 		strcpy(s, buf);
     32 	return buf;
     33 }