2
0
mirror of git://gcc.gnu.org/git/gcc.git synced 2024-12-24 04:58:57 +08:00
gcc/libiberty/tmpnam.c
Michael Hayes 348425392f * tmpnam.c (L_tmpnam): Fix typo.
From-SVN: r26921
1999-05-12 19:23:42 -06:00

40 lines
618 B
C

#include <stdio.h>
#ifndef L_tmpnam
#define L_tmpnam 100
#endif
#ifndef P_tmpdir
#define P_tmpdir "/usr/tmp"
#endif
static char tmpnam_buffer[L_tmpnam];
static int tmpnam_counter;
extern int getpid ();
char *
tmpnam (s)
char *s;
{
int pid = getpid ();
if (s == NULL)
s = tmpnam_buffer;
/* Generate the filename and make sure that there isn't one called
it already. */
while (1)
{
FILE *f;
sprintf (s, "%s/%s%x.%x", P_tmpdir, "t", pid, tmpnam_counter);
f = fopen (s, "r");
if (f == NULL)
break;
tmpnam_counter++;
fclose (f);
}
return s;
}