Uninitialized vector entry?
[minix3.git] / lib / stdio / tmpnam.c
blob71e5f13c2a73b2bd9c53afc22ed151b46b00557b
1 /*
2 * tmpnam.c - create a unique filename
3 */
4 /* $Header$ */
6 #if defined(_POSIX_SOURCE)
7 #include <sys/types.h>
8 #endif
9 #include <stdio.h>
10 #include <string.h>
11 #include "loc_incl.h"
13 pid_t _getpid(void);
15 char *
16 tmpnam(char *s) {
17 static char name_buffer[L_tmpnam] = "/tmp/tmp.";
18 static unsigned long count = 0;
19 static char *name = NULL;
21 if (!name) {
22 name = name_buffer + strlen(name_buffer);
23 name = _i_compute((unsigned long)_getpid(), 10, name, 5);
24 *name++ = '.';
25 *name = '\0';
27 if (++count > TMP_MAX) count = 1; /* wrap-around */
28 *_i_compute(count, 10, name, 3) = '\0';
29 if (s) return strcpy(s, name_buffer);
30 else return name_buffer;