/* FUNCTION <>---create a large temporary file INDEX tmpfile64 INDEX _tmpfile64_r SYNOPSIS #include FILE *tmpfile64(void); FILE *_tmpfile64_r(void *<[reent]>); DESCRIPTION Create a large temporary file (a file which will be deleted automatically), using a name generated by <>. 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 <> and <<_tmpfile64_r>> are only defined if __LARGE64_FILES is defined. RETURNS <> normally returns a pointer to the temporary file. If no temporary file could be created, the result is NULL, and <> records the reason for failure. PORTABILITY <> is a glibc extension. Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>, <>, <>. <> also requires the global pointer <>. */ #include #include #include #include #include #ifndef O_BINARY # define O_BINARY 0 #endif #ifdef __LARGE64_FILES FILE * _tmpfile64_r (struct _reent *ptr) { FILE *fp; int e; char *f; char buf[L_tmpnam]; 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 && _REENT_ERRNO(ptr) == EEXIST); if (fd < 0) return NULL; fp = _fdopen64_r (ptr, fd, "wb+"); e = _REENT_ERRNO(ptr); if (!fp) _close_r (ptr, fd); (void) _remove_r (ptr, f); _REENT_ERRNO(ptr) = e; return fp; } #ifndef _REENT_ONLY FILE * tmpfile64 (void) { return _tmpfile64_r (_REENT); } #endif #endif /* __LARGE64_FILES */