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