ReactOS  0.4.15-dev-1187-g119f102
_stdio_file.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
11  * Permission to use or copy this software for any purpose is hereby granted
12  * without fee, provided the above notices are retained on all copies.
13  * Permission to modify the code and to distribute modified code is granted,
14  * provided the above notices are retained, and a notice that the code was
15  * modified is included with the above copyright notice.
16  *
17  */
18 
19 #ifndef _STLP_STDIO_FILE_H
20 #define _STLP_STDIO_FILE_H
21 
22 /* This file provides a low-level interface between the internal
23  * representation of struct FILE, from the C stdio library, and
24  * the C++ I/O library. */
25 
26 #ifndef _STLP_CSTDIO
27 # include <cstdio>
28 #endif
29 #ifndef _STLP_CSTDDEF
30 # include <cstddef>
31 #endif
32 
33 #if defined (__MSL__)
34 # include <unix.h> /* get the definition of fileno */
35 #endif
36 
38 
39 #if defined (_STLP_WCE)
40 
41 inline int _FILE_fd(const FILE *__f) {
42  /* Check if FILE is one of the three standard streams
43  We do this check first, because invoking _fileno() on one of them
44  causes a terminal window to be created. This also happens if you do
45  any IO on them, but merely retrieving the filedescriptor shouldn't
46  already do that.
47 
48  Obviously this is pretty implementation-specific because it requires
49  that indeed the first three FDs are always the same, but that is not
50  only common but almost guaranteed. */
51  for (int __fd = 0; __fd != 3; ++__fd) {
52  if (__f == _getstdfilex(__fd))
53  return __fd;
54  }
55 
56  /* Normal files. */
57  return (int)::_fileno((FILE*)__f);
58 }
59 
60 # elif defined (_STLP_SCO_OPENSERVER) || defined (__NCR_SVR)
61 
62 inline int _FILE_fd(const FILE *__f) { return __f->__file; }
63 
64 # elif defined (__sun) && defined (_LP64)
65 
66 inline int _FILE_fd(const FILE *__f) { return (int) __f->__pad[2]; }
67 
68 #elif defined (__hpux) /* && defined(__hppa) && defined(__HP_aCC)) */ || \
69  defined (__MVS__) || \
70  defined (_STLP_USE_UCLIBC) /* should be before _STLP_USE_GLIBC */
71 
72 inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE*, __f)); }
73 
74 #elif defined (_STLP_USE_GLIBC)
75 
76 inline int _FILE_fd(const FILE *__f) { return __f->_fileno; }
77 
78 #elif defined (__BORLANDC__)
79 
80 inline int _FILE_fd(const FILE *__f) { return __f->fd; }
81 
82 #elif defined (__MWERKS__)
83 
84 /* using MWERKS-specific defines here to detect other OS targets
85  * dwa: I'm not sure they provide fileno for all OS's, but this should
86  * work for Win32 and WinCE
87 
88  * Hmm, at least for Novell NetWare __dest_os == __mac_os true too..
89  * May be both __dest_os and __mac_os defined and empty? - ptr */
90 # if __dest_os == __mac_os
91 inline int _FILE_fd(const FILE *__f) { return ::fileno(__CONST_CAST(FILE*, __f)); }
92 # else
93 inline int _FILE_fd(const FILE *__f) { return ::_fileno(__CONST_CAST(FILE*, __f)); }
94 # endif
95 
96 #elif defined (__QNXNTO__) || defined (__WATCOMC__) || defined (__EMX__)
97 
98 inline int _FILE_fd(const FILE *__f) { return __f->_handle; }
99 
100 #elif defined (__Lynx__)
101 
102 /* the prototypes are taken from LynxOS patch for STLport 4.0 */
103 inline int _FILE_fd(const FILE *__f) { return __f->_fd; }
104 
105 #else /* The most common access to file descriptor. */
106 
107 inline int _FILE_fd(const FILE *__f) { return __f->_file; }
108 
109 #endif
110 
112 
113 #endif /* _STLP_STDIO_FILE_H */
114 
115 /* Local Variables:
116  * mode:C++
117  * End: */
_STLP_BEGIN_NAMESPACE int _FILE_fd(const FILE *__f)
Definition: _stdio_file.h:107
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
#define __CONST_CAST(__x, __y)
Definition: features.h:584
#define _STLP_END_NAMESPACE
Definition: features.h:503
int _file
Definition: mbstring.h:24
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)