Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / stdio / tmpfile.c
1 /*
2  * tmpfile.c - create and open a temporary file
3  */
4 /* $Id: tmpfile.c,v 1.4 1994/06/24 11:51:47 ceriel Exp $ */
5
6 #include        <stdio.h>
7 #include        <string.h>
8 #include        "loc_incl.h"
9
10 unsigned int _getpid(void);
11
12 FILE *
13 tmpfile(void) {
14         static char name_buffer[L_tmpnam] = "/tmp/tmp." ;
15         static char *name = NULL;
16         FILE *file;
17
18         if (!name) {
19                 name = name_buffer + strlen(name_buffer);
20                 name = _i_compute(_getpid(), 10, name, 5);
21                 *name = '\0';
22         }
23
24         file = fopen(name_buffer,"wb+");
25         if (!file) return (FILE *)NULL;
26         (void) remove(name_buffer);
27         return file;
28 }