Category : Files from Magazines
Archive   : CUJ9202.ZIP
Filename : 1002014C

 
Output of file : 1002014C contained in archive : CUJ9202.ZIP


Listing 3 -- the file tmpnam.c

/* tmpnam function -- UNIX version */
#include
#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);
}