fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / stdio / tmpfile.c
blobc38e61d3437b7e9f20426fde9a1596d0f3062511
1 /*
2 FUNCTION
3 <<tmpfile>>---create a temporary file
5 INDEX
6 tmpfile
7 INDEX
8 _tmpfile_r
10 ANSI_SYNOPSIS
11 #include <stdio.h>
12 FILE *tmpfile(void);
14 FILE *_tmpfile_r(void *<[reent]>);
16 TRAD_SYNOPSIS
17 #include <stdio.h>
18 FILE *tmpfile();
20 FILE *_tmpfile_r(<[reent]>)
21 char *<[reent]>;
23 DESCRIPTION
24 Create a temporary file (a file which will be deleted automatically),
25 using a name generated by <<tmpnam>>. The temporary file is opened with
26 the mode <<"wb+">>, permitting you to read and write anywhere in it
27 as a binary file (without any data transformations the host system may
28 perform for text files).
30 The alternate function <<_tmpfile_r>> is a reentrant version. The
31 argument <[reent]> is a pointer to a reentrancy structure.
33 RETURNS
34 <<tmpfile>> normally returns a pointer to the temporary file. If no
35 temporary file could be created, the result is NULL, and <<errno>>
36 records the reason for failure.
38 PORTABILITY
39 Both ANSI C and the System V Interface Definition (Issue 2) require
40 <<tmpfile>>.
42 Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>,
43 <<isatty>>, <<lseek>>, <<open>>, <<read>>, <<sbrk>>, <<write>>.
45 <<tmpfile>> also requires the global pointer <<environ>>.
48 #include <stdio.h>
49 #include <errno.h>
51 FILE *
52 _DEFUN (_tmpfile_r, (ptr),
53 struct _reent *ptr)
55 FILE *fp;
56 int e;
57 char *f;
58 char buf[L_tmpnam];
60 if ((f = _tmpnam_r (ptr, buf)) == NULL)
61 return NULL;
62 fp = _fopen_r (ptr, f, "wb+");
63 e = ptr->_errno;
64 _CAST_VOID _remove_r (ptr, f);
65 ptr->_errno = e;
66 return fp;
69 #ifndef _REENT_ONLY
71 FILE *
72 _DEFUN_VOID (tmpfile)
74 return _tmpfile_r (_REENT);
77 #endif