home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_02
/
1002014c
< prev
next >
Wrap
Text File
|
1991-12-17
|
563b
|
31 lines
Listing 3 -- the file tmpnam.c
/* tmpnam function -- UNIX version */
#include <string.h>
#include "xstdio.h"
/* UNIX system call */
int _Getpid(void);
char *(tmpnam)(char *s)
{ /* create a temporary file name */
int i;
char *p;
unsigned short t;
static char buf[L_tmpnam];
static unsigned short seed = 0;
if (s == NULL)
s = buf;
seed = seed == 0 ? _Getpid() : seed + 1;
strcpy(s, "/tmp/t");
i = 5;
p = s + strlen(s) + i;
*p = '\0';
for (t = seed; 0 <= --i; t >>= 3)
*--p = '0' + (t & 07);
return (s);
}