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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [stdio64/] [fdopen64.c] - Blame information for rev 858

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

Line No. Rev Author Line
1 148 jeremybenn
/*
2
FUNCTION
3
<<fdopen64>>---turn open file into a stream
4
 
5
INDEX
6
        fdopen64
7
INDEX
8
        _fdopen64_r
9
 
10
SYNOPSIS
11
        #include <stdio.h>
12
        FILE *fdopen64(int <[fd]>, const char *<[mode]>);
13
        FILE *_fdopen64_r(void *<[reent]>,
14
                     int <[fd]>, const char *<[mode]>);
15
 
16
DESCRIPTION
17
<<fdopen64>> produces a file descriptor of type <<FILE *>>, from a
18
descriptor for an already-open file (returned, for example, by the
19
system subroutine <<open>> rather than by <<fopen>>).
20
The <[mode]> argument has the same meanings as in <<fopen>>.
21
 
22
RETURNS
23
File pointer or <<NULL>>, as for <<fopen>>.
24
*/
25
 
26
#include <sys/types.h>
27
#include <sys/fcntl.h>
28
 
29
#include <stdio.h>
30
#include <errno.h>
31
#include "local.h"
32
#include <_syslist.h>
33
#include <sys/lock.h>
34
 
35
extern int __sflags ();
36
 
37
FILE *
38
_DEFUN (_fdopen64_r, (ptr, fd, mode),
39
        struct _reent *ptr _AND
40
        int fd _AND
41
        _CONST char *mode)
42
{
43
  register FILE *fp;
44
  int flags, oflags;
45
#ifdef HAVE_FCNTL
46
  int fdflags, fdmode;
47
#endif
48
 
49
  if ((flags = __sflags (ptr, mode, &oflags)) == 0)
50
    return 0;
51
 
52
  /* make sure the mode the user wants is a subset of the actual mode */
53
#ifdef HAVE_FCNTL
54
  if ((fdflags = _fcntl_r (ptr, fd, F_GETFL, 0)) < 0)
55
    return 0;
56
  fdmode = fdflags & O_ACCMODE;
57
  if (fdmode != O_RDWR && (fdmode != (oflags & O_ACCMODE)))
58
    {
59
      ptr->_errno = EBADF;
60
      return 0;
61
    }
62
#endif
63
 
64
  if ((fp = __sfp (ptr)) == 0)
65
    return 0;
66
 
67
  _flockfile(fp);
68
 
69
  fp->_flags = flags;
70
  /* POSIX recommends setting the O_APPEND bit on fd to match append
71
     streams.  Someone may later clear O_APPEND on fileno(fp), but the
72
     stream must still remain in append mode.  Rely on __sflags
73
     setting __SAPP properly.  */
74
#ifdef HAVE_FCNTL
75
  if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
76
    _fcntl_r (ptr, fd, F_SETFL, fdflags | O_APPEND);
77
#endif
78
  fp->_file = fd;
79
  fp->_cookie = (_PTR) fp;
80
 
81
#undef _read
82
#undef _write
83
#undef _seek
84
#undef _close
85
 
86
  fp->_read = __sread;
87
  fp->_write = __swrite64;
88
  fp->_seek = __sseek;
89
  fp->_seek64 = __sseek64;
90
  fp->_close = __sclose;
91
 
92
#ifdef __SCLE
93
  /* Explicit given mode results in explicit setting mode on fd */
94
  if (oflags & O_BINARY)
95
    setmode(fp->_file, O_BINARY);
96
  else if (oflags & O_TEXT)
97
    setmode(fp->_file, O_TEXT);
98
  if (__stextmode(fp->_file))
99
    fp->_flags |= __SCLE;
100
#endif
101
 
102
  fp->_flags |= __SL64;
103
 
104
  _funlockfile(fp);
105
  return fp;
106
}
107
 
108
#ifndef _REENT_ONLY
109
 
110
FILE *
111
_DEFUN (fdopen64, (fd, mode),
112
        int fd _AND
113
        _CONST char *mode)
114
{
115
  return _fdopen64_r (_REENT, fd, mode);
116
}
117
 
118
#endif

powered by: WebSVN 2.1.0

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