Rev | Line | |
---|
[9] | 1 | /*
|
---|
| 2 | * tmpfile.c - create and open a temporary file
|
---|
| 3 | */
|
---|
| 4 | /* $Header: /cvsup/minix/src/lib/stdio/tmpfile.c,v 1.1.1.1 2005/04/21 14:56:36 beng Exp $ */
|
---|
| 5 |
|
---|
| 6 | #if defined(_POSIX_SOURCE)
|
---|
| 7 | #include <sys/types.h>
|
---|
| 8 | #endif
|
---|
| 9 | #include <stdio.h>
|
---|
| 10 | #include <string.h>
|
---|
| 11 | #include "loc_incl.h"
|
---|
| 12 |
|
---|
| 13 | pid_t _getpid(void);
|
---|
| 14 |
|
---|
| 15 | FILE *
|
---|
| 16 | tmpfile(void) {
|
---|
| 17 | static char name_buffer[L_tmpnam] = "/tmp/tmp." ;
|
---|
| 18 | static char *name = NULL;
|
---|
| 19 | FILE *file;
|
---|
| 20 |
|
---|
| 21 | if (!name) {
|
---|
| 22 | name = name_buffer + strlen(name_buffer);
|
---|
| 23 | name = _i_compute(_getpid(), 10, name, 5);
|
---|
| 24 | *name = '\0';
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | file = fopen(name_buffer,"wb+");
|
---|
| 28 | if (!file) return (FILE *)NULL;
|
---|
| 29 | (void) remove(name_buffer);
|
---|
| 30 | return file;
|
---|
| 31 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.