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

34 lines
531 B
C
Raw Normal View History

1989-05-30 13:34:25 +00:00
/*
* tmpfile.c - create and open a temporary file
*/
1994-06-24 14:02:31 +00:00
/* $Id$ */
1989-05-30 13:34:25 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.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
FILE* tmpfile(void)
{
static char name_buffer[L_tmpnam] = ACK_TMP_PREFIX;
2018-06-21 20:33:47 +00:00
static char* name = NULL;
FILE* file;
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-06-26 10:37:05 +00:00
*name = '\0';
1989-05-30 13:34:25 +00:00
}
2018-06-21 20:33:47 +00:00
file = fopen(name_buffer, "wb+");
if (!file)
return (FILE*)NULL;
(void)remove(name_buffer);
1989-05-30 13:34:25 +00:00
return file;
}
2018-06-23 16:54:40 +00:00
#endif