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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdio/] [tmpfile.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 1010 ivang
/*
2
FUNCTION
3
<<tmpfile>>---create a temporary file
4
 
5
INDEX
6
        tmpfile
7
INDEX
8
        _tmpfile_r
9
 
10
ANSI_SYNOPSIS
11
        #include <stdio.h>
12
        FILE *tmpfile(void);
13
 
14
        FILE *_tmpfile_r(void *<[reent]>);
15
 
16
TRAD_SYNOPSIS
17
        #include <stdio.h>
18
        FILE *tmpfile();
19
 
20
        FILE *_tmpfile_r(<[reent]>)
21
        char *<[reent]>;
22
 
23
DESCRIPTION
24
Create a 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).
29
 
30
The alternate function <<_tmpfile_r>> is a reentrant version.  The
31
argument <[reent]> is a pointer to a reentrancy structure.
32
 
33
RETURNS
34
<<tmpfile>> normally returns a pointer to the temporary file.  If no
35
temporary file could be created, the result is NULL, and <<errno>>
36
records the reason for failure.
37
 
38
PORTABILITY
39
Both ANSI C and the System V Interface Definition (Issue 2) require
40
<<tmpfile>>.
41
 
42
Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>,
43
<<isatty>>, <<lseek>>, <<open>>, <<read>>, <<sbrk>>, <<write>>.
44
 
45
<<tmpfile>> also requires the global pointer <<environ>>.
46
*/
47
 
48
#include <stdio.h>
49
#include <errno.h>
50
 
51
FILE *
52
_DEFUN (_tmpfile_r, (ptr),
53
        struct _reent *ptr)
54
{
55
  FILE *fp;
56
  int e;
57
  char *f;
58
  char buf[L_tmpnam];
59
 
60
  if ((f = _tmpnam_r (ptr, buf)) == NULL)
61
    return NULL;
62
  fp = fopen (f, "wb+");
63
  e = ptr->_errno;
64
  _CAST_VOID remove (f);
65
  ptr->_errno = e;
66
  return fp;
67
}
68
 
69
#ifndef _REENT_ONLY
70
 
71
FILE *
72
_DEFUN_VOID (tmpfile)
73
{
74
  return _tmpfile_r (_REENT);
75
}
76
 
77
#endif

powered by: WebSVN 2.1.0

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