xref: /plan9/sys/src/ape/lib/ap/stdio/tmpnam.c (revision 2d069fea74dfcc83c6858e715bf74862cb64720a)
1 /*
2  * pANS stdio -- tmpnam
3  */
4 #include "iolib.h"
5 #include <string.h>
6 
7 char *
tmpnam(char * s)8 tmpnam(char *s)
9 {
10 	static char name[] = "/tmp/tn000000000000";
11 	char *p;
12 
13 	do {
14 		p = name + 7;
15 		while (*p == '9')
16 			*p++ = '0';
17 		if (*p == '\0')
18 			return NULL;
19 		++*p;
20 	} while (access(name, 0) == 0);
21 	if (s) {
22 		strcpy(s, name);
23 		return s;
24 	}
25 	return name;
26 }
27 
28 
29 char *
tmpnam_r(char * s)30 tmpnam_r(char *s)
31 {
32 	return s ? tmpnam(s) : NULL;
33 }
34