Initial revision
This commit is contained in:
28
lang/cem/libcc.ansi/stdio/tmpnam.c
Normal file
28
lang/cem/libcc.ansi/stdio/tmpnam.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* tmpnam.c - create a unique filename
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
unsigned int getpid(void);
|
||||
|
||||
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);
|
||||
*name++ = '.';
|
||||
*name++ = '\0';
|
||||
}
|
||||
if (++count > TMP_MAX) count = 1; /* wrap-around */
|
||||
*i_compute(count, 10, name, 3) = '\0';
|
||||
if (s) return strcpy(s, name_buffer);
|
||||
else return name_buffer;
|
||||
}
|
||||
Reference in New Issue
Block a user