OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [stdio64/] [tmpfile64.c] - Blame information for rev 258

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
FUNCTION
3
<<tmpfile64>>---create a large temporary file
4
 
5
INDEX
6
        tmpfile64
7
INDEX
8
        _tmpfile64_r
9
 
10
ANSI_SYNOPSIS
11
        #include <stdio.h>
12
        FILE *tmpfile64(void);
13
 
14
        FILE *_tmpfile64_r(void *<[reent]>);
15
 
16
TRAD_SYNOPSIS
17
        #include <stdio.h>
18
        FILE *tmpfile64();
19
 
20
        FILE *_tmpfile64_r(<[reent]>)
21
        char *<[reent]>;
22
 
23
DESCRIPTION
24
Create a large 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).  The file may be larger than 2GB.
29
 
30
The alternate function <<_tmpfile64_r>> is a reentrant version.  The
31
argument <[reent]> is a pointer to a reentrancy structure.
32
 
33
Both <<tmpfile64>> and <<_tmpfile64_r>> are only defined if __LARGE64_FILES
34
is defined.
35
 
36
RETURNS
37
<<tmpfile64>> normally returns a pointer to the temporary file.  If no
38
temporary file could be created, the result is NULL, and <<errno>>
39
records the reason for failure.
40
 
41
PORTABILITY
42
<<tmpfile64>> is a glibc extension.
43
 
44
Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>,
45
<<isatty>>, <<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>.
46
 
47
<<tmpfile64>> also requires the global pointer <<environ>>.
48
*/
49
 
50
#include <stdio.h>
51
#include <reent.h>
52
#include <errno.h>
53
#include <fcntl.h>
54
#include <sys/stat.h>
55
 
56
#ifndef O_BINARY
57
# define O_BINARY 0
58
#endif
59
 
60
#ifdef __LARGE64_FILES
61
 
62
FILE *
63
_DEFUN (_tmpfile64_r, (ptr),
64
        struct _reent *ptr)
65
{
66
  FILE *fp;
67
  int e;
68
  char *f;
69
  char buf[L_tmpnam];
70
  int fd;
71
 
72
  do
73
  {
74
     if ((f = _tmpnam_r (ptr, buf)) == NULL)
75
        return NULL;
76
      fd = _open64_r (ptr, f, O_RDWR | O_CREAT | O_EXCL | O_BINARY,
77
                      S_IRUSR | S_IWUSR);
78
  }
79
  while (fd < 0 && ptr->_errno == EEXIST);
80
  if (fd < 0)
81
    return NULL;
82
  fp = _fdopen64_r (ptr, fd, "wb+");
83
  e = ptr->_errno;
84
  if (!fp)
85
    _close_r (ptr, fd);
86
  _CAST_VOID _remove_r (ptr, f);
87
  ptr->_errno = e;
88
  return fp;
89
}
90
 
91
#ifndef _REENT_ONLY
92
 
93
FILE *
94
_DEFUN_VOID (tmpfile64)
95
{
96
  return _tmpfile64_r (_REENT);
97
}
98
 
99
#endif
100
 
101
#endif /* __LARGE64_FILES */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.