michael@0: /* michael@0: * Copyright (c) 1999 michael@0: * Silicon Graphics Computer Systems, Inc. michael@0: * michael@0: * Copyright (c) 1999 michael@0: * Boris Fomitchev michael@0: * michael@0: * This material is provided "as is", with absolutely no warranty expressed michael@0: * or implied. Any use is at your own risk. michael@0: * michael@0: * Permission to use or copy this software for any purpose is hereby granted michael@0: * without fee, provided the above notices are retained on all copies. michael@0: * Permission to modify the code and to distribute modified code is granted, michael@0: * provided the above notices are retained, and a notice that the code was michael@0: * modified is included with the above copyright notice. michael@0: * michael@0: */ michael@0: michael@0: #ifndef _STLP_STDIO_FILE_H michael@0: #define _STLP_STDIO_FILE_H michael@0: michael@0: /* This file provides a low-level interface between the internal michael@0: * representation of struct FILE, from the C stdio library, and michael@0: * the C++ I/O library. */ michael@0: michael@0: #ifndef _STLP_CSTDIO michael@0: # include michael@0: #endif michael@0: #ifndef _STLP_CSTDDEF michael@0: # include michael@0: #endif michael@0: michael@0: #if defined (__MSL__) michael@0: # include /* get the definition of fileno */ michael@0: #endif michael@0: michael@0: _STLP_BEGIN_NAMESPACE michael@0: michael@0: #if defined (_STLP_WCE) michael@0: michael@0: inline int _FILE_fd(const FILE *__f) { michael@0: /* Check if FILE is one of the three standard streams michael@0: We do this check first, because invoking _fileno() on one of them michael@0: causes a terminal window to be created. This also happens if you do michael@0: any IO on them, but merely retrieving the filedescriptor shouldn't michael@0: already do that. michael@0: michael@0: Obviously this is pretty implementation-specific because it requires michael@0: that indeed the first three FDs are always the same, but that is not michael@0: only common but almost guaranteed. */ michael@0: for (int __fd = 0; __fd != 3; ++__fd) { michael@0: if (__f == _getstdfilex(__fd)) michael@0: return __fd; michael@0: } michael@0: michael@0: /* Normal files. */ michael@0: return (int)::_fileno((FILE*)__f); michael@0: } michael@0: michael@0: # elif defined (_STLP_SCO_OPENSERVER) || defined (__NCR_SVR) michael@0: michael@0: inline int _FILE_fd(const FILE *__f) { return __f->__file; } michael@0: michael@0: # elif defined (__sun) && defined (_LP64) michael@0: michael@0: inline int _FILE_fd(const FILE *__f) { return (int) __f->__pad[2]; } michael@0: michael@0: #elif defined (__hpux) /* && defined(__hppa) && defined(__HP_aCC)) */ || \ michael@0: defined (__MVS__) || \ michael@0: defined (_STLP_USE_UCLIBC) /* should be before _STLP_USE_GLIBC */ michael@0: michael@0: inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE*, __f)); } michael@0: michael@0: #elif defined (_STLP_USE_GLIBC) michael@0: michael@0: inline int _FILE_fd(const FILE *__f) { return __f->_fileno; } michael@0: michael@0: #elif defined (__BORLANDC__) michael@0: michael@0: inline int _FILE_fd(const FILE *__f) { return __f->fd; } michael@0: michael@0: #elif defined (__MWERKS__) michael@0: michael@0: /* using MWERKS-specific defines here to detect other OS targets michael@0: * dwa: I'm not sure they provide fileno for all OS's, but this should michael@0: * work for Win32 and WinCE michael@0: michael@0: * Hmm, at least for Novell NetWare __dest_os == __mac_os true too.. michael@0: * May be both __dest_os and __mac_os defined and empty? - ptr */ michael@0: # if __dest_os == __mac_os michael@0: inline int _FILE_fd(const FILE *__f) { return ::fileno(__CONST_CAST(FILE*, __f)); } michael@0: # else michael@0: inline int _FILE_fd(const FILE *__f) { return ::_fileno(__CONST_CAST(FILE*, __f)); } michael@0: # endif michael@0: michael@0: #elif defined (__QNXNTO__) || defined (__WATCOMC__) || defined (__EMX__) michael@0: michael@0: inline int _FILE_fd(const FILE *__f) { return __f->_handle; } michael@0: michael@0: #elif defined (__Lynx__) michael@0: michael@0: /* the prototypes are taken from LynxOS patch for STLport 4.0 */ michael@0: inline int _FILE_fd(const FILE *__f) { return __f->_fd; } michael@0: michael@0: #else /* The most common access to file descriptor. */ michael@0: michael@0: inline int _FILE_fd(const FILE *__f) { return __f->_file; } michael@0: michael@0: #endif michael@0: michael@0: _STLP_END_NAMESPACE michael@0: michael@0: #endif /* _STLP_STDIO_FILE_H */ michael@0: michael@0: /* Local Variables: michael@0: * mode:C++ michael@0: * End: */