1 | /* |
---|
2 | FUNCTION |
---|
3 | <<tmpfile64>>---create a large temporary file |
---|
4 | |
---|
5 | INDEX |
---|
6 | tmpfile64 |
---|
7 | INDEX |
---|
8 | _tmpfile64_r |
---|
9 | |
---|
10 | SYNOPSIS |
---|
11 | #include <stdio.h> |
---|
12 | FILE *tmpfile64(void); |
---|
13 | |
---|
14 | FILE *_tmpfile64_r(void *<[reent]>); |
---|
15 | |
---|
16 | DESCRIPTION |
---|
17 | Create a large temporary file (a file which will be deleted automatically), |
---|
18 | using a name generated by <<tmpnam>>. The temporary file is opened with |
---|
19 | the mode <<"wb+">>, permitting you to read and write anywhere in it |
---|
20 | as a binary file (without any data transformations the host system may |
---|
21 | perform for text files). The file may be larger than 2GB. |
---|
22 | |
---|
23 | The alternate function <<_tmpfile64_r>> is a reentrant version. The |
---|
24 | argument <[reent]> is a pointer to a reentrancy structure. |
---|
25 | |
---|
26 | Both <<tmpfile64>> and <<_tmpfile64_r>> are only defined if __LARGE64_FILES |
---|
27 | is defined. |
---|
28 | |
---|
29 | RETURNS |
---|
30 | <<tmpfile64>> normally returns a pointer to the temporary file. If no |
---|
31 | temporary file could be created, the result is NULL, and <<errno>> |
---|
32 | records the reason for failure. |
---|
33 | |
---|
34 | PORTABILITY |
---|
35 | <<tmpfile64>> is a glibc extension. |
---|
36 | |
---|
37 | Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>, |
---|
38 | <<isatty>>, <<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>. |
---|
39 | |
---|
40 | <<tmpfile64>> also requires the global pointer <<environ>>. |
---|
41 | */ |
---|
42 | |
---|
43 | #include <stdio.h> |
---|
44 | #include <reent.h> |
---|
45 | #include <errno.h> |
---|
46 | #include <fcntl.h> |
---|
47 | #include <sys/stat.h> |
---|
48 | |
---|
49 | #ifndef O_BINARY |
---|
50 | # define O_BINARY 0 |
---|
51 | #endif |
---|
52 | |
---|
53 | #ifdef __LARGE64_FILES |
---|
54 | |
---|
55 | FILE * |
---|
56 | _tmpfile64_r (struct _reent *ptr) |
---|
57 | { |
---|
58 | FILE *fp; |
---|
59 | int e; |
---|
60 | char *f; |
---|
61 | char buf[L_tmpnam]; |
---|
62 | int fd; |
---|
63 | |
---|
64 | do |
---|
65 | { |
---|
66 | if ((f = _tmpnam_r (ptr, buf)) == NULL) |
---|
67 | return NULL; |
---|
68 | fd = _open64_r (ptr, f, O_RDWR | O_CREAT | O_EXCL | O_BINARY, |
---|
69 | S_IRUSR | S_IWUSR); |
---|
70 | } |
---|
71 | while (fd < 0 && ptr->_errno == EEXIST); |
---|
72 | if (fd < 0) |
---|
73 | return NULL; |
---|
74 | fp = _fdopen64_r (ptr, fd, "wb+"); |
---|
75 | e = ptr->_errno; |
---|
76 | if (!fp) |
---|
77 | _close_r (ptr, fd); |
---|
78 | (void) _remove_r (ptr, f); |
---|
79 | ptr->_errno = e; |
---|
80 | return fp; |
---|
81 | } |
---|
82 | |
---|
83 | #ifndef _REENT_ONLY |
---|
84 | |
---|
85 | FILE * |
---|
86 | tmpfile64 (void) |
---|
87 | { |
---|
88 | return _tmpfile64_r (_REENT); |
---|
89 | } |
---|
90 | |
---|
91 | #endif |
---|
92 | |
---|
93 | #endif /* __LARGE64_FILES */ |
---|