|
Last change
on this file since 108 was 10, checked in by bird, 23 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
618 bytes
|
| Line | |
|---|
| 1 | #include <stdio.h>
|
|---|
| 2 |
|
|---|
| 3 | #ifndef L_tmpnam
|
|---|
| 4 | #define L_tmpnam 100
|
|---|
| 5 | #endif
|
|---|
| 6 | #ifndef P_tmpdir
|
|---|
| 7 | #define P_tmpdir "/usr/tmp"
|
|---|
| 8 | #endif
|
|---|
| 9 |
|
|---|
| 10 | static char tmpnam_buffer[L_tmpnam];
|
|---|
| 11 | static int tmpnam_counter;
|
|---|
| 12 |
|
|---|
| 13 | extern int getpid ();
|
|---|
| 14 |
|
|---|
| 15 | char *
|
|---|
| 16 | tmpnam (s)
|
|---|
| 17 | char *s;
|
|---|
| 18 | {
|
|---|
| 19 | int pid = getpid ();
|
|---|
| 20 |
|
|---|
| 21 | if (s == NULL)
|
|---|
| 22 | s = tmpnam_buffer;
|
|---|
| 23 |
|
|---|
| 24 | /* Generate the filename and make sure that there isn't one called
|
|---|
| 25 | it already. */
|
|---|
| 26 |
|
|---|
| 27 | while (1)
|
|---|
| 28 | {
|
|---|
| 29 | FILE *f;
|
|---|
| 30 | sprintf (s, "%s/%s%x.%x", P_tmpdir, "t", pid, tmpnam_counter);
|
|---|
| 31 | f = fopen (s, "r");
|
|---|
| 32 | if (f == NULL)
|
|---|
| 33 | break;
|
|---|
| 34 | tmpnam_counter++;
|
|---|
| 35 | fclose (f);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | return s;
|
|---|
| 39 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.