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
37
_STLP_BEGIN_NAMESPACE
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
      defined (__ANDROID__)         /* should be before _STLP_USE_GLIBC */
72
73
inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE*, __f)); }
74
75
#elif defined (_STLP_USE_GLIBC)
76
77
inline int _FILE_fd(const FILE *__f) { return __f->_fileno; }
78
79
#elif defined (__BORLANDC__)
80
81
inline int _FILE_fd(const FILE *__f) { return __f->fd; }
82
83
#elif defined (__QNXNTO__) || defined (__WATCOMC__) || defined (__EMX__)
84
85
inline int _FILE_fd(const FILE *__f) { return __f->_handle; }
86
87
#elif defined (__Lynx__)
88
89
/* the prototypes are taken from LynxOS patch for STLport 4.0 */
90
inline int _FILE_fd(const FILE *__f) { return __f->_fd; }
91
92
#else  /* The most common access to file descriptor. */
93
94
inline int _FILE_fd(const FILE *__f) { return __f->_file; }
95
96
#endif
97
98
_STLP_END_NAMESPACE
99
100
#endif /* _STLP_STDIO_FILE_H */
101
102
/* Local Variables:
103
 * mode: C++
104
 * End:
105
 */