1TMPFILE(P)                 POSIX Programmer's Manual                TMPFILE(P)
2
3
4

NAME

6       tmpfile - create a temporary file
7

SYNOPSIS

9       #include <stdio.h>
10
11       FILE *tmpfile(void);
12
13

DESCRIPTION

15       The  tmpfile() function shall create a temporary file and open a corre‐
16       sponding stream. The file shall be automatically deleted when all  ref‐
17       erences  to  the  file are closed. The file is opened as in fopen() for
18       update (w+).
19
20       In some implementations, a permanent file may be  left  behind  if  the
21       process  calling  tmpfile()  is killed while it is processing a call to
22       tmpfile().
23
24       An error message may be written to standard error if the stream  cannot
25       be opened.
26

RETURN VALUE

28       Upon  successful  completion,  tmpfile()  shall return a pointer to the
29       stream of the file that is created. Otherwise, it shall return  a  null
30       pointer    and set errno to indicate the error.
31

ERRORS

33       The tmpfile() function shall fail if:
34
35       EINTR  A signal was caught during tmpfile().
36
37       EMFILE {OPEN_MAX}  file  descriptors  are currently open in the calling
38              process.
39
40       ENFILE The maximum allowable number of files is currently open  in  the
41              system.
42
43       ENOSPC The  directory  or  file system which would contain the new file
44              cannot be expanded.
45
46       EOVERFLOW
47              The file is a regular file and the size of the  file  cannot  be
48              represented correctly in an object of type off_t.
49
50
51       The tmpfile() function may fail if:
52
53       EMFILE {FOPEN_MAX} streams are currently open in the calling process.
54
55       ENOMEM Insufficient storage space is available.
56
57
58       The following sections are informative.
59

EXAMPLES

61   Creating a Temporary File
62       The  following example creates a temporary file for update, and returns
63       a pointer to a stream for the created file in the fp variable.
64
65
66              #include <stdio.h>
67              ...
68              FILE *fp;
69
70
71              fp = tmpfile ();
72

APPLICATION USAGE

74       It should be possible to open at least {TMP_MAX} temporary files during
75       the  lifetime  of  the program (this limit may be shared with tmpnam())
76       and there should be no limit on the number  simultaneously  open  other
77       than  this  limit  and  any  limit  on  the  number  of  open  files  (
78       {FOPEN_MAX}).
79

RATIONALE

81       None.
82

FUTURE DIRECTIONS

84       None.
85

SEE ALSO

87       fopen() ,  tmpnam()  ,  unlink()  ,  the  Base  Definitions  volume  of
88       IEEE Std 1003.1-2001, <stdio.h>
89
91       Portions  of  this text are reprinted and reproduced in electronic form
92       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
93       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
94       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
95       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
96       event of any discrepancy between this version and the original IEEE and
97       The  Open Group Standard, the original IEEE and The Open Group Standard
98       is the referee document. The original Standard can be  obtained  online
99       at http://www.opengroup.org/unix/online.html .
100
101
102
103IEEE/The Open Group                  2003                           TMPFILE(P)
Impressum