_stdio_file.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef _STLP_STDIO_FILE_H
  19. #define _STLP_STDIO_FILE_H
  20. /* This file provides a low-level interface between the internal
  21. * representation of struct FILE, from the C stdio library, and
  22. * the C++ I/O library. */
  23. #ifndef _STLP_CSTDIO
  24. # include <cstdio>
  25. #endif
  26. #ifndef _STLP_CSTDDEF
  27. # include <cstddef>
  28. #endif
  29. #if defined (__MSL__)
  30. # include <unix.h> /* get the definition of fileno */
  31. #endif
  32. _STLP_BEGIN_NAMESPACE
  33. #if defined (_STLP_WCE)
  34. inline int _FILE_fd(const FILE *__f) {
  35. /* Check if FILE is one of the three standard streams
  36. We do this check first, because invoking _fileno() on one of them
  37. causes a terminal window to be created. This also happens if you do
  38. any IO on them, but merely retrieving the filedescriptor shouldn't
  39. already do that.
  40. Obviously this is pretty implementation-specific because it requires
  41. that indeed the first three FDs are always the same, but that is not
  42. only common but almost guaranteed. */
  43. for (int __fd = 0; __fd != 3; ++__fd) {
  44. if (__f == _getstdfilex(__fd))
  45. return __fd;
  46. }
  47. /* Normal files. */
  48. return (int)::_fileno((FILE*)__f);
  49. }
  50. # elif defined (_STLP_SCO_OPENSERVER) || defined (__NCR_SVR)
  51. inline int _FILE_fd(const FILE *__f) { return __f->__file; }
  52. # elif defined (__sun) && defined (_LP64)
  53. inline int _FILE_fd(const FILE *__f) { return (int) __f->__pad[2]; }
  54. #elif defined (__hpux) /* && defined(__hppa) && defined(__HP_aCC)) */ || \
  55. defined (__MVS__) || \
  56. defined (_STLP_USE_UCLIBC) /* should be before _STLP_USE_GLIBC */
  57. inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE*, __f)); }
  58. #elif defined (_STLP_USE_GLIBC)
  59. inline int _FILE_fd(const FILE *__f) { return __f->_fileno; }
  60. #elif defined (__BORLANDC__)
  61. inline int _FILE_fd(const FILE *__f) { return __f->fd; }
  62. #elif defined (__MWERKS__)
  63. /* using MWERKS-specific defines here to detect other OS targets
  64. * dwa: I'm not sure they provide fileno for all OS's, but this should
  65. * work for Win32 and WinCE
  66. * Hmm, at least for Novell NetWare __dest_os == __mac_os true too..
  67. * May be both __dest_os and __mac_os defined and empty? - ptr */
  68. # if __dest_os == __mac_os
  69. inline int _FILE_fd(const FILE *__f) { return ::fileno(__CONST_CAST(FILE*, __f)); }
  70. # else
  71. inline int _FILE_fd(const FILE *__f) { return ::_fileno(__CONST_CAST(FILE*, __f)); }
  72. # endif
  73. #elif defined (__QNXNTO__) || defined (__WATCOMC__) || defined (__EMX__)
  74. inline int _FILE_fd(const FILE *__f) { return __f->_handle; }
  75. #elif defined (__Lynx__)
  76. /* the prototypes are taken from LynxOS patch for STLport 4.0 */
  77. inline int _FILE_fd(const FILE *__f) { return __f->_fd; }
  78. #else /* The most common access to file descriptor. */
  79. inline int _FILE_fd(const FILE *__f) { return __f->_file; }
  80. #endif
  81. _STLP_END_NAMESPACE
  82. #endif /* _STLP_STDIO_FILE_H */
  83. /* Local Variables:
  84. * mode:C++
  85. * End: */