Repository navigation
<
8000
/div>
Expand file tree
/
Copy pathtmpnam.c
More file actions
executable file
·31 lines (27 loc) · 655 Bytes
/
Copy pathtmpnam.c
File metadata and controls
executable file
·31 lines (27 loc) · 655 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* tmpnam.c - create a unique filename
*/
/* $Header$ */
#if defined(_POSIX_SOURCE)
#include <sys/types.h>
#endif
#include <stdio.h>
#include <string.h>
#include "loc_incl.h"
pid_t _getpid(void);
char *
tmpnam(char *s) {
static char name_buffer[L_tmpnam] = "/tmp/tmp.";
static unsigned long count = 0;
static char *name = NULL;
if (!name) {
name = name_buffer + strlen(name_buffer);
name = _i_compute((unsigned long)_getpid(), 10, name, 5);
*name++ = '.';
*name = '\0';
}
if (++count > TMP_MAX) count = 1; /* wrap-around */
*_i_compute(count, 10, name, 3) = '\0';
if (s) return strcpy(s, name_buffer);
else return name_buffer;
}