source: trunk/libs/newlib/src/newlib/libc/stdio64/tmpfile64.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.9 KB
Line 
1/*
2FUNCTION
3<<tmpfile64>>---create a large temporary file
4
5INDEX
6        tmpfile64
7INDEX
8        _tmpfile64_r
9
10SYNOPSIS
11        #include <stdio.h>
12        FILE *tmpfile64(void);
13
14        FILE *_tmpfile64_r(void *<[reent]>);
15
16DESCRIPTION
17Create a large temporary file (a file which will be deleted automatically),
18using a name generated by <<tmpnam>>.  The temporary file is opened with
19the mode <<"wb+">>, permitting you to read and write anywhere in it
20as a binary file (without any data transformations the host system may
21perform for text files).  The file may be larger than 2GB.
22
23The alternate function <<_tmpfile64_r>> is a reentrant version.  The
24argument <[reent]> is a pointer to a reentrancy structure.
25
26Both <<tmpfile64>> and <<_tmpfile64_r>> are only defined if __LARGE64_FILES
27is defined.
28
29RETURNS
30<<tmpfile64>> normally returns a pointer to the temporary file.  If no
31temporary file could be created, the result is NULL, and <<errno>>
32records the reason for failure.
33
34PORTABILITY
35<<tmpfile64>> is a glibc extension.
36
37Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>,
38<<isatty>>, <<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>.
39
40<<tmpfile64>> also requires the global pointer <<environ>>.
41*/
42
43#include <stdio.h>
44#include <reent.h>
45#include <errno.h>
46#include <fcntl.h>
47#include <sys/stat.h>
48
49#ifndef O_BINARY
50# define O_BINARY 0
51#endif
52
53#ifdef __LARGE64_FILES
54
55FILE *
56_tmpfile64_r (struct _reent *ptr)
57{
58  FILE *fp;
59  int e;
60  char *f;
61  char buf[L_tmpnam];
62  int fd;
63
64  do
65  {
66     if ((f = _tmpnam_r (ptr, buf)) == NULL)
67        return NULL;
68      fd = _open64_r (ptr, f, O_RDWR | O_CREAT | O_EXCL | O_BINARY,
69                      S_IRUSR | S_IWUSR);
70  }
71  while (fd < 0 && ptr->_errno == EEXIST);
72  if (fd < 0)
73    return NULL;
74  fp = _fdopen64_r (ptr, fd, "wb+");
75  e = ptr->_errno;
76  if (!fp)
77    _close_r (ptr, fd);
78  (void) _remove_r (ptr, f);
79  ptr->_errno = e;
80  return fp;
81}
82
83#ifndef _REENT_ONLY
84
85FILE *
86tmpfile64 (void)
87{
88  return _tmpfile64_r (_REENT);
89}
90
91#endif
92
93#endif /* __LARGE64_FILES */
Note: See TracBrowser for help on using the repository browser.