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

37 lines
636 B
C
Raw Normal View History

1989-05-30 13:34:25 +00:00
/*
* tmpnam.c - create a unique filename
*/
1994-06-24 14:02:31 +00:00
/* $Id$ */
1989-05-30 13:34:25 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "loc_incl.h"
1989-05-30 13:34:25 +00:00
2018-06-23 16:54:40 +00:00
#if ACKCONF_WANT_STDIO
2018-06-21 20:33:47 +00:00
char* tmpnam(char* s)
{
static char name_buffer[L_tmpnam] = ACK_TMP_PREFIX;
1989-05-30 13:34:25 +00:00
static unsigned long count = 0;
2018-06-21 20:33:47 +00:00
static char* name = NULL;
1989-05-30 13:34:25 +00:00
2018-06-21 20:33:47 +00:00
if (!name)
{
1989-05-30 13:34:25 +00:00
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
}
2018-06-21 20:33:47 +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';
2018-06-21 20:33:47 +00:00
if (s)
return strcpy(s, name_buffer);
else
return name_buffer;
1989-05-30 13:34:25 +00:00
}
2018-06-23 16:54:40 +00:00
#endif