1 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
2 /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
3 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
4 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
6 #include <msvcrt/stdio.h>
7 #include <msvcrt/string.h>
8 #include <msvcrt/stdlib.h>
9 #include <msvcrt/errno.h>
10 #include <msvcrt/fcntl.h>
11 //#include <msvcrt/unistd.h>
12 #include <msvcrt/io.h>
13 #include <msvcrt/share.h>
14 #include <msvcrt/internal/file.h>
17 FILE * __alloc_file(void);
24 char *temp_name = tmpnam(0);
25 char *n_t_r = (char *)malloc(L_tmpnam);
30 /* We could have a race condition, whereby another program
31 (in another virtual machine, or if the temporary file is
32 in a directory which is shared via a network) opens the
33 file returned by `tmpnam' between the call above and the
34 moment when we actually open the file below. This loop
35 retries the call to `tmpnam' until we actually succeed
36 to create the file which didn't exist before. */
39 temp_fd = _open(temp_name, 0, SH_DENYRW);
40 // if ( errno == ENOENT )
42 } while (temp_fd == -1 && (temp_name = tmpnam(0)) != 0);
47 /* This should have been fdopen(temp_fd, "wb+"), but `fdopen'
48 is non-ANSI. So we need to dump some of its guts here. Sigh... */
55 f->_flag = _IORMONCL | _IOREAD | _IOWRT;
56 f->_name_to_remove = n_t_r;
57 strcpy(f->_name_to_remove, temp_name);
58 f->_base = f->_ptr = NULL;