2002-07-18 07:25:44 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<tmpfile64>>---create a large temporary file
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
tmpfile64
|
|
|
|
INDEX
|
|
|
|
_tmpfile64_r
|
|
|
|
|
|
|
|
ANSI_SYNOPSIS
|
|
|
|
#include <stdio.h>
|
|
|
|
FILE *tmpfile64(void);
|
|
|
|
|
|
|
|
FILE *_tmpfile64_r(void *<[reent]>);
|
|
|
|
|
|
|
|
TRAD_SYNOPSIS
|
|
|
|
#include <stdio.h>
|
|
|
|
FILE *tmpfile64();
|
|
|
|
|
|
|
|
FILE *_tmpfile64_r(<[reent]>)
|
|
|
|
char *<[reent]>;
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Create a large temporary file (a file which will be deleted automatically),
|
|
|
|
using a name generated by <<tmpnam>>. The temporary file is opened with
|
|
|
|
the mode <<"wb+">>, permitting you to read and write anywhere in it
|
|
|
|
as a binary file (without any data transformations the host system may
|
|
|
|
perform for text files). The file may be larger than 2GB.
|
|
|
|
|
|
|
|
The alternate function <<_tmpfile64_r>> is a reentrant version. The
|
|
|
|
argument <[reent]> is a pointer to a reentrancy structure.
|
|
|
|
|
|
|
|
Both <<tmpfile64>> and <<_tmpfile64_r>> are only defined if __LARGE64_FILES
|
|
|
|
is defined.
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
<<tmpfile64>> normally returns a pointer to the temporary file. If no
|
|
|
|
temporary file could be created, the result is NULL, and <<errno>>
|
|
|
|
records the reason for failure.
|
|
|
|
|
|
|
|
PORTABILITY
|
|
|
|
<<tmpfile64>> is a glibc extension.
|
|
|
|
|
|
|
|
Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>,
|
|
|
|
<<isatty>>, <<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>.
|
|
|
|
|
|
|
|
<<tmpfile64>> also requires the global pointer <<environ>>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2007-07-14 04:37:53 +08:00
|
|
|
#include <reent.h>
|
2002-07-18 07:25:44 +08:00
|
|
|
#include <errno.h>
|
2007-05-17 04:06:08 +08:00
|
|
|
#include <fcntl.h>
|
2007-05-17 20:10:29 +08:00
|
|
|
#include <sys/stat.h>
|
2007-05-17 04:06:08 +08:00
|
|
|
|
|
|
|
#ifndef O_BINARY
|
|
|
|
# define O_BINARY 0
|
|
|
|
#endif
|
2002-07-18 07:25:44 +08:00
|
|
|
|
2002-08-27 02:56:09 +08:00
|
|
|
#ifdef __LARGE64_FILES
|
|
|
|
|
2002-07-18 07:25:44 +08:00
|
|
|
FILE *
|
|
|
|
_DEFUN (_tmpfile64_r, (ptr),
|
|
|
|
struct _reent *ptr)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int e;
|
|
|
|
char *f;
|
|
|
|
char buf[L_tmpnam];
|
2007-05-17 04:06:08 +08:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((f = _tmpnam_r (ptr, buf)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
fd = _open64_r (ptr, f, O_RDWR | O_CREAT | O_EXCL | O_BINARY,
|
|
|
|
S_IRUSR | S_IWUSR);
|
|
|
|
}
|
|
|
|
while (fd < 0 && ptr->_errno == EEXIST);
|
|
|
|
if (fd < 0)
|
2002-07-18 07:25:44 +08:00
|
|
|
return NULL;
|
2007-05-17 04:06:08 +08:00
|
|
|
fp = _fdopen64_r (ptr, fd, "wb+");
|
2002-07-18 07:25:44 +08:00
|
|
|
e = ptr->_errno;
|
2007-05-17 04:06:08 +08:00
|
|
|
if (!fp)
|
|
|
|
_close_r (ptr, fd);
|
2003-08-27 02:09:43 +08:00
|
|
|
_CAST_VOID _remove_r (ptr, f);
|
2002-07-18 07:25:44 +08:00
|
|
|
ptr->_errno = e;
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
|
|
|
|
FILE *
|
|
|
|
_DEFUN_VOID (tmpfile64)
|
|
|
|
{
|
|
|
|
return _tmpfile64_r (_REENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __LARGE64_FILES */
|