ack/lang/cem/libcc.ansi/stdio/tmpnam.c

29 lines
590 B
C
Raw Normal View History

1989-05-30 13:34:25 +00:00
/*
* tmpnam.c - create a unique filename
*/
/* $Header$ */
#include <stdio.h>
#include <string.h>
#include "loc_incl.h"
unsigned int _getpid(void);
1989-05-30 13:34:25 +00:00
char *
tmpnam(char *s) {
static char name_buffer[L_tmpnam] = "/tmp/tmp.";
static unsigned long count = 0;
static char *name = NULL;
if (!name) {
name = name_buffer + strlen(name_buffer);
name = _i_compute(_getpid(), 10, name, 5);
1989-05-30 13:34:25 +00:00
*name++ = '.';
*name = '\0';
1989-05-30 13:34:25 +00:00
}
if (++count > TMP_MAX) count = 1; /* wrap-around */
1989-06-26 10:37:05 +00:00
*_i_compute(count, 10, name, 3) = '\0';
1989-05-30 13:34:25 +00:00
if (s) return strcpy(s, name_buffer);
else return name_buffer;
}