Line | |
---|
1 | /*
|
---|
2 | * tmpnam.c - create a unique filename
|
---|
3 | */
|
---|
4 | /* $Header: /cvsup/minix/src/lib/stdio/tmpnam.c,v 1.1.1.1 2005/04/21 14:56:36 beng Exp $ */
|
---|
5 |
|
---|
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"
|
---|
12 |
|
---|
13 | pid_t _getpid(void);
|
---|
14 |
|
---|
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;
|
---|
20 |
|
---|
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';
|
---|
26 | }
|
---|
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;
|
---|
31 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.