/home/ntakagi/work/STLport-5.1.5/src/_stdio_file.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 00019 00020 // WARNING: This is an internal header file, included by other C++ 00021 // standard library headers. You should not attempt to use this header 00022 // file directly. 00023 00024 00025 #ifndef _STLP_STDIO_FILE_H 00026 #define _STLP_STDIO_FILE_H 00027 00028 // This file provides a low-level interface between the internal 00029 // representation of struct FILE, from the C stdio library, and 00030 // the C++ I/O library. The C++ I/O library views a FILE object as 00031 // a collection of three pointers: the beginning of the buffer, the 00032 // current read/write position, and the end of the buffer. 00033 00034 // The interface: 00035 // - char* _FILE_[IO]_begin(const FILE *__f); 00036 // Returns a pointer to the beginning of the buffer. 00037 // - char* _FILE_[IO]_next(const FILE *__f); 00038 // Returns the current read/write position within the buffer. 00039 // - char* _FILE_[IO]_end(const FILE *__f); 00040 // Returns a pointer immediately past the end of the buffer. 00041 // - char* _FILE_[IO]_avail(const FILE *__f); 00042 // Returns the number of characters remaining in the buffer, i.e. 00043 // _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f). 00044 // - char& _FILE_[IO]_preincr(FILE *__f) 00045 // Increments the current read/write position by 1, returning the 00046 // character at the old position. 00047 // - char& _FILE_[IO]_postincr(FILE *__f) 00048 // Increments the current read/write position by 1, returning the 00049 // character at the old position. 00050 // - char& _FILE_[IO]_predecr(FILE *__f) 00051 // Decrements the current read/write position by 1, returning the 00052 // character at the old position. 00053 // - char& _FILE_[IO]_postdecr(FILE *__f) 00054 // Decrements the current read/write position by 1, returning the 00055 // character at the old position. 00056 // - void _FILE_[IO]_bump(FILE *__f, int __n) 00057 // Increments the current read/write position by __n. 00058 // - void _FILE_[IO]_set(FILE *__f, char* __begin, char* __next, char* __end); 00059 // Sets the beginning of the bufer to __begin, the current read/write 00060 // position to __next, and the buffer's past-the-end pointer to __end. 00061 // If any of those pointers is null, then all of them must be null. 00062 00063 // Each function comes in two versions, one for a FILE used as an input 00064 // buffer and one for a FILE used as an output buffer. In some stdio 00065 // implementations the two functions are identical, but in others they are 00066 // not. 00067 00068 #ifndef _STLP_CSTDIO 00069 # include <cstdio> 00070 #endif 00071 #ifndef _STLP_CSTDDEF 00072 # include <cstddef> 00073 #endif 00074 00075 #if defined(__MSL__) && !defined(N_PLAT_NLM) 00076 # include <unix.h> // get the definition of fileno 00077 #endif 00078 00079 _STLP_BEGIN_NAMESPACE 00080 00081 //---------------------------------------------------------------------- 00082 // Implementation for eMbedded Visual C++ 3.0 and 4.2 (.NET) 00083 #if defined (_STLP_WCE) 00084 00085 inline int _FILE_fd(const FILE *__f) 00086 { 00087 /* check if FILE is one of the three standard streams 00088 We do this check first, because invoking _fileno() on one of them 00089 causes a terminal window to be created. This also happens if you do 00090 any IO on them, but merely retrieving the filedescriptor shouldn't 00091 already do that. 00092 00093 Obviously this is pretty implementation-specific because it requires 00094 that indeed the first three FDs are always the same, but that is not 00095 only common but almost guaranteed. */ 00096 for( int __fd=0; __fd!=3; ++__fd) 00097 { 00098 if(__f == _getstdfilex(__fd)) 00099 return __fd; 00100 } 00101 00102 return (int)::_fileno((FILE*)__f); 00103 } 00104 00105 # undef _STLP_FILE_I_O_IDENTICAL 00106 00107 // Implementation for the IRIX C library. 00108 // Solaris interface looks to be identical. 00109 #elif !defined(_STLP_USE_GLIBC) && \ 00110 ( defined(__sgi) || \ 00111 ( defined(__sun) && ! defined (_LP64) ) || \ 00112 defined (__osf__) || defined(__DECCXX) || \ 00113 (defined (_STLP_MSVC) && !defined (_STLP_WCE_EVC3)) || \ 00114 defined (__ICL) || defined (__MINGW32__) || defined(__DJGPP) || defined (_AIX) || defined (_CRAY)) 00115 00116 #if defined (_STLP_MSVC) || defined (__ICL) || defined (__MINGW32__) || defined(__DJGPP) 00117 typedef char* _File_ptr_type; 00118 #else 00119 typedef unsigned char* _File_ptr_type; 00120 #endif 00121 00122 inline int _FILE_fd(const FILE *__f) { return __f->_file; } 00123 inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_base; } 00124 inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_ptr; } 00125 inline char* _FILE_I_end(const FILE *__f) 00126 { return (char*) __f->_ptr + __f->_cnt; } 00127 00128 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; } 00129 00130 inline char& _FILE_I_preincr(FILE *__f) 00131 { --__f->_cnt; return *(char*) (++__f->_ptr); } 00132 inline char& _FILE_I_postincr(FILE *__f) 00133 { --__f->_cnt; return *(char*) (__f->_ptr++); } 00134 inline char& _FILE_I_predecr(FILE *__f) 00135 { ++__f->_cnt; return *(char*) (--__f->_ptr); } 00136 inline char& _FILE_I_postdecr(FILE *__f) 00137 { ++__f->_cnt; return *(char*) (__f->_ptr--); } 00138 inline void _FILE_I_bump(FILE *__f, int __n) 00139 { __f->_ptr += __n; __f->_cnt -= __n; } 00140 00141 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00142 __f->_base = (_File_ptr_type) __begin; 00143 __f->_ptr = (_File_ptr_type) __next; 00144 __f->_cnt = __end - __next; 00145 } 00146 00147 # define _STLP_FILE_I_O_IDENTICAL 1 00148 00149 #elif defined(__EMX__) 00150 00151 inline int _FILE_fd(const FILE* __f) { return __f->_handle; } 00152 inline char* _FILE_I_begin(const FILE* __f) { return (char*) __f->_buffer; } 00153 inline char* _FILE_I_next(const FILE* __f) { return (char*) __f->_ptr; } 00154 inline char* _FILE_I_end(const FILE* __f) { return (char *) __f->_ptr + __f->_rcount; } 00155 inline ptrdiff_t _FILE_I_avail(const FILE* __f) { return __f->_rcount; } 00156 inline char& _FILE_I_preincr(FILE* __f) { --__f->_rcount; return *(char*) (++__f->_ptr); } 00157 inline char& _FILE_I_postincr(FILE* __f) { --__f->_rcount; return *(char*) (__f->_ptr++); } 00158 inline char& _FILE_I_predecr(FILE* __f) { ++__f->_rcount; return *(char*) (--__f->_ptr); } 00159 inline char& _FILE_I_postdecr(FILE* __f) { ++__f->_rcount; return *(char*) (__f->_ptr--); } 00160 inline void _FILE_I_bump(FILE* __f, int __n) { __f->_ptr += __n; __f->_rcount -= __n; } 00161 inline void _FILE_I_set(FILE* __f, char* __begin, char* __next, char* __end) { 00162 __f->_buffer = __begin; 00163 __f->_ptr = __next; 00164 __f->_rcount = __end - __next; 00165 } 00166 00167 inline char* _FILE_O_begin(const FILE* __f) { return (char*) __f->_buffer; } 00168 inline char* _FILE_O_next(const FILE* __f) { return (char*) __f->_ptr; } 00169 inline char* _FILE_O_end(const FILE* __f) { return (char*) __f->_ptr + __f->_wcount; } 00170 inline ptrdiff_t _FILE_O_avail(const FILE* __f) { return __f->_wcount; } 00171 inline char& _FILE_O_preincr(FILE* __f) { --__f->_wcount; return *(char*) (++__f->_ptr); } 00172 inline char& _FILE_O_postincr(FILE* __f) { --__f->_wcount; return *(char*) (__f->_ptr++); } 00173 inline char& _FILE_O_predecr(FILE* __f) { ++__f->_wcount; return *(char*) (--__f->_ptr); } 00174 inline char& _FILE_O_postdecr(FILE* __f) { ++__f->_wcount; return *(char*) (__f->_ptr--); } 00175 inline void _FILE_O_bump(FILE* __f, int __n) { __f->_ptr += __n; __f->_wcount -= __n; } 00176 inline void _FILE_O_set(FILE* __f, char* __begin, char* __next, char* __end) { 00177 __f->_buffer = __begin; 00178 __f->_ptr = __next; 00179 __f->_wcount = __end - __next; 00180 } 00181 00182 00183 # undef _STLP_FILE_I_O_IDENTICAL 00184 00185 # elif defined(_STLP_SCO_OPENSERVER) || defined(__NCR_SVR) 00186 00187 typedef unsigned char* _File_ptr_type; 00188 00189 inline int _FILE_fd(const FILE *__f) { return __f->__file; } 00190 inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->__base; } 00191 inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->__ptr; } 00192 inline char* _FILE_I_end(const FILE *__f) 00193 { return (char*) __f->__ptr + __f->__cnt; } 00194 00195 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->__cnt; } 00196 00197 inline char& _FILE_I_preincr(FILE *__f) 00198 { --__f->__cnt; return *(char*) (++__f->__ptr); } 00199 inline char& _FILE_I_postincr(FILE *__f) 00200 { --__f->__cnt; return *(char*) (__f->__ptr++); } 00201 inline char& _FILE_I_predecr(FILE *__f) 00202 { ++__f->__cnt; return *(char*) (--__f->__ptr); } 00203 inline char& _FILE_I_postdecr(FILE *__f) 00204 { ++__f->__cnt; return *(char*) (__f->__ptr--); } 00205 inline void _FILE_I_bump(FILE *__f, int __n) 00206 { __f->__ptr += __n; __f->__cnt -= __n; } 00207 00208 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00209 __f->__base = (_File_ptr_type) __begin; 00210 __f->__ptr = (_File_ptr_type) __next; 00211 __f->__cnt = __end - __next; 00212 } 00213 00214 # define _STLP_FILE_I_O_IDENTICAL 1 00215 00216 # elif defined(__sun) && defined( _LP64) 00217 00218 typedef long _File_ptr_type; 00219 00220 inline int _FILE_fd(const FILE *__f) { return (int) __f->__pad[2]; } 00221 inline char* _FILE_I_begin(const FILE *__f) { return (char*) 00222 __f->__pad[1]; } 00223 inline char* _FILE_I_next(const FILE *__f) { return (char*) 00224 __f->__pad[0]; } 00225 inline char* _FILE_I_end(const FILE *__f) 00226 { return (char*) __f->__pad[0] + __f->__pad[3]; } 00227 00228 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->__pad[3]; } 00229 00230 inline char& _FILE_I_preincr(FILE *__f) 00231 { --__f->__pad[3]; return *(char*) (++__f->__pad[0]); } 00232 inline char& _FILE_I_postincr(FILE *__f) 00233 { --__f->__pad[3]; return *(char*) (__f->__pad[0]++); } 00234 inline char& _FILE_I_predecr(FILE *__f) 00235 { ++__f->__pad[3]; return *(char*) (--__f->__pad[0]); } 00236 inline char& _FILE_I_postdecr(FILE *__f) 00237 { ++__f->__pad[3]; return *(char*) (__f->__pad[0]--); } 00238 inline void _FILE_I_bump(FILE *__f, long __n) 00239 { __f->__pad[0] += __n; __f->__pad[3] -= __n; } 00240 00241 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* 00242 __end) { 00243 __f->__pad[1] = (_File_ptr_type) __begin; 00244 __f->__pad[0] = (_File_ptr_type) __next; 00245 __f->__pad[3] = __end - __next; 00246 } 00247 00248 # define _STLP_FILE_I_O_IDENTICAL 00249 00250 #elif defined (__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ 00251 || defined(__amigaos__) || ( defined(__GNUC__) && defined(__APPLE__) ) 00252 00253 inline int _FILE_fd(const FILE *__f) { return __f->_file; } 00254 inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_bf._base; } 00255 inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_p; } 00256 inline char* _FILE_I_end(const FILE *__f) 00257 { return (char*) __f->_p + __f->_r; } 00258 00259 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_r; } 00260 00261 #if ( defined(__GNUC__) && defined(__APPLE__) ) 00262 inline char& _FILE_I_preincr(FILE *__f) 00263 { --__f->_r; return *(char*) (++__f->_p); } 00264 inline char& _FILE_I_postincr(FILE *__f) 00265 { --__f->_r; return *(char*) (__f->_p++); } 00266 inline char& _FILE_I_predecr(FILE *__f) 00267 { ++__f->_r; return *(char*) (--__f->_p); } 00268 inline char& _FILE_I_postdecr(FILE *__f) 00269 { ++__f->_r; return *(char*) (__f->_p--); } 00270 inline void _FILE_I_bump(FILE *__f, int __n) 00271 { __f->_p += __n; __f->_r -= __n; } 00272 #else 00273 inline char& _FILE_I_preincr(FILE *__f) 00274 { --__f->_r; --__f->_bf._size; return *(char*) (++__f->_p); } 00275 inline char& _FILE_I_postincr(FILE *__f) 00276 { --__f->_r; --__f->_bf._size; return *(char*) (__f->_p++); } 00277 inline char& _FILE_I_predecr(FILE *__f) 00278 { ++__f->_r; ++ __f->_bf._size; return *(char*) (--__f->_p); } 00279 inline char& _FILE_I_postdecr(FILE *__f) 00280 { ++__f->_r; ++__f->_bf._size; return *(char*) (__f->_p--); } 00281 inline void _FILE_I_bump(FILE *__f, int __n) 00282 { __f->_p += __n; __f->_bf._size+=__n; __f->_r -= __n; } 00283 #endif 00284 00285 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00286 __f->_bf._base = (unsigned char*) __begin; 00287 __f->_p = (unsigned char*) __next; 00288 __f->_r = __f->_bf._size = __end - __next; 00289 } 00290 inline char* _FILE_O_begin(const FILE *__f) { return (char*) __f->_bf._base; } 00291 inline char* _FILE_O_next(const FILE *__f) { return (char*) __f->_p; } 00292 inline char* _FILE_O_end(const FILE *__f) 00293 { return (char*) __f->_p + __f->_w; } 00294 00295 inline ptrdiff_t _FILE_O_avail(const FILE *__f) { return __f->_w; } 00296 00297 #if ( defined(__GNUC__) && defined(__APPLE__) ) 00298 inline char& _FILE_O_preincr(FILE *__f) 00299 { --__f->_w; return *(char*) (++__f->_p); } 00300 inline char& _FILE_O_postincr(FILE *__f) 00301 { --__f->_w; return *(char*) (__f->_p++); } 00302 inline char& _FILE_O_predecr(FILE *__f) 00303 { ++__f->_w; return *(char*) (--__f->_p); } 00304 inline char& _FILE_O_postdecr(FILE *__f) 00305 { ++__f->_w; return *(char*) (__f->_p--); } 00306 inline void _FILE_O_bump(FILE *__f, int __n) 00307 { __f->_p += __n; __f->_w -= __n; } 00308 #else 00309 inline char& _FILE_O_preincr(FILE *__f) 00310 { --__f->_w; --__f->_bf._size; return *(char*) (++__f->_p); } 00311 inline char& _FILE_O_postincr(FILE *__f) 00312 { --__f->_w; --__f->_bf._size; return *(char*) (__f->_p++); } 00313 inline char& _FILE_O_predecr(FILE *__f) 00314 { ++__f->_w; ++__f->_bf._size; return *(char*) (--__f->_p); } 00315 inline char& _FILE_O_postdecr(FILE *__f) 00316 { ++__f->_w; ++__f->_bf._size; return *(char*) (__f->_p--); } 00317 inline void _FILE_O_bump(FILE *__f, int __n) 00318 { __f->_p += __n; __f->_bf._size+=__n; __f->_w -= __n; } 00319 #endif 00320 00321 inline void _FILE_O_set(FILE *__f, char* __begin, char* __next, char* __end) { 00322 __f->_bf._base = (unsigned char*) __begin; 00323 __f->_p = (unsigned char*) __next; 00324 __f->_w = __f->_bf._size = __end - __next; 00325 } 00326 00327 # undef _STLP_FILE_I_O_IDENTICAL 00328 00329 #elif defined(_STLP_USE_UCLIBC) /* should be before _STLP_USE_GLIBC */ 00330 inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE *,__f)); } 00331 #elif defined(_STLP_USE_GLIBC) 00332 00333 inline int _FILE_fd(const FILE *__f) { return __f->_fileno; } 00334 inline char* _FILE_I_begin(const FILE *__f) { return __f->_IO_read_base; } 00335 inline char* _FILE_I_next(const FILE *__f) { return __f->_IO_read_ptr; } 00336 inline char* _FILE_I_end(const FILE *__f) { return __f->_IO_read_end; } 00337 00338 inline ptrdiff_t _FILE_I_avail(const FILE *__f) 00339 { return __f->_IO_read_end - __f->_IO_read_ptr; } 00340 00341 inline char& _FILE_I_preincr(FILE *__f) { return *++__f->_IO_read_ptr; } 00342 inline char& _FILE_I_postincr(FILE *__f) { return *__f->_IO_read_ptr++; } 00343 inline char& _FILE_I_predecr(FILE *__f) { return *--__f->_IO_read_ptr; } 00344 inline char& _FILE_I_postdecr(FILE *__f) { return *__f->_IO_read_ptr--; } 00345 inline void _FILE_I_bump(FILE *__f, int __n) { __f->_IO_read_ptr += __n; } 00346 00347 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00348 __f->_IO_read_base = __begin; 00349 __f->_IO_read_ptr = __next; 00350 __f->_IO_read_end = __end; 00351 } 00352 00353 inline char* _FILE_O_begin(const FILE *__f) { return __f->_IO_write_base; } 00354 inline char* _FILE_O_next(const FILE *__f) { return __f->_IO_write_ptr; } 00355 inline char* _FILE_O_end(const FILE *__f) { return __f->_IO_write_end; } 00356 00357 inline ptrdiff_t _FILE_O_avail(const FILE *__f) 00358 { return __f->_IO_write_end - __f->_IO_write_ptr; } 00359 00360 inline char& _FILE_O_preincr(FILE *__f) { return *++__f->_IO_write_ptr; } 00361 inline char& _FILE_O_postincr(FILE *__f) { return *__f->_IO_write_ptr++; } 00362 inline char& _FILE_O_predecr(FILE *__f) { return *--__f->_IO_write_ptr; } 00363 inline char& _FILE_O_postdecr(FILE *__f) { return *__f->_IO_write_ptr--; } 00364 inline void _FILE_O_bump(FILE *__f, int __n) { __f->_IO_write_ptr += __n; } 00365 00366 inline void _FILE_O_set(FILE *__f, char* __begin, char* __next, char* __end) { 00367 __f->_IO_write_base = __begin; 00368 __f->_IO_write_ptr = __next; 00369 __f->_IO_write_end = __end; 00370 00371 } 00372 00373 #elif defined(__hpux) /* && defined(__hppa) && defined(__HP_aCC)) */ 00374 00375 #ifndef _INCLUDE_HPUX_SOURCE 00376 extern "C" unsigned char *__bufendtab[]; 00377 # undef _bufend 00378 # define _bufend(__p) \ 00379 (*(((__p)->__flag & _IOEXT) ? &(((_FILEX *)(__p))->__bufendp) \ 00380 : &(__bufendtab[(__p) - __iob]))) 00381 00382 # define _bufsiz(__p) (_bufend(__p) - (__p)->__base) 00383 #endif /* _INCLUDE_HPUX_SOURCE */ 00384 00385 #if defined(_STLP_HPACC_BROKEN_BUFEND) 00386 # undef _bufend 00387 # define _bufend(__p) \ 00388 (*(((__p)->__flag & _IOEXT) ? &((__REINTERPRET_CAST(_FILEX*,(__p)))->__bufendp) \ 00389 : &(__bufendtab[__REINTERPRET_CAST(FILE*,(__p)) - __iob]))) 00390 #endif 00391 00392 inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE *,__f)); } 00393 inline char* _FILE_I_begin(const FILE *__f) { return (__REINTERPRET_CAST(char*, __f->__base)); } 00394 inline char* _FILE_I_next(const FILE *__f) { return (__REINTERPRET_CAST(char*, __f->__ptr)); } 00395 inline char* _FILE_I_end(const FILE *__f) { return (__REINTERPRET_CAST(char*, __f->__ptr +__f->__cnt)); } 00396 00397 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->__cnt; } 00398 00399 inline char& _FILE_I_preincr(FILE *__f) { --__f->__cnt; return *__REINTERPRET_CAST(char*, ++__f->__ptr); } 00400 inline char& _FILE_I_postincr(FILE *__f) { --__f->__cnt; return *__REINTERPRET_CAST(char*, __f->__ptr++); } 00401 inline char& _FILE_I_predecr(FILE *__f) { ++__f->__cnt; return *__REINTERPRET_CAST(char*,--__f->__ptr); } 00402 inline char& _FILE_I_postdecr(FILE *__f) { ++__f->__cnt; return *__REINTERPRET_CAST(char*,__f->__ptr--); } 00403 inline void _FILE_I_bump(FILE *__f, int __n) { __f->__cnt -= __n; __f->__ptr += __n; } 00404 00405 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00406 # if defined(__hpux) 00407 if( (unsigned long) (__f - &__iob[0]) > _NFILE) 00408 __f->__flag |= _IOEXT; // used by stdio's _bufend macro and goodness knows what else... 00409 # endif 00410 __f->__cnt = __end - __next; 00411 __f->__base = __REINTERPRET_CAST(unsigned char*, __begin); 00412 __f->__ptr = __REINTERPRET_CAST(unsigned char*, __next); 00413 _bufend(__f) = __REINTERPRET_CAST(unsigned char*, __end); 00414 } 00415 00416 // For HPUX stdio, input and output FILE manipulation is identical. 00417 00418 # define _STLP_FILE_I_O_IDENTICAL 00419 00420 #elif defined (__BORLANDC__) 00421 00422 typedef unsigned char* _File_ptr_type; 00423 00424 inline int _FILE_fd(const FILE *__f) { return __f->fd; } 00425 inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->buffer; 00426 } 00427 inline char* _FILE_I_next(const FILE *__f) 00428 { return (char*)__f->curp; } 00429 inline char* _FILE_I_end(const FILE *__f) 00430 { return (char*) __f->curp + __f->level; } 00431 00432 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->level; } 00433 00434 inline char& _FILE_I_preincr(FILE *__f) 00435 { --__f->level; return *(char*) (++__f->curp); } 00436 inline char& _FILE_I_postincr(FILE *__f) 00437 { --__f->level; return *(char*) (__f->curp++); } 00438 inline char& _FILE_I_predecr(FILE *__f) 00439 { ++__f->level; return *(char*) (--__f->curp); } 00440 inline char& _FILE_I_postdecr(FILE *__f) 00441 { ++__f->level; return *(char*) (__f->curp--); } 00442 inline void _FILE_I_bump(FILE *__f, int __n) 00443 { __f->curp += __n; __f->level -= __n; } 00444 00445 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00446 __f->buffer = (_File_ptr_type) __begin; 00447 __f->curp = (_File_ptr_type) __next; 00448 __f->level = __end - __next; 00449 } 00450 00451 # define _STLP_FILE_I_O_IDENTICAL 00452 00453 #elif defined( __MWERKS__ ) 00454 00455 // using MWERKS-specific defines here to detect other OS targets 00456 // dwa: I'm not sure they provide fileno for all OS's, but this should 00457 // work for Win32 and WinCE 00458 00459 #ifndef N_PLAT_NLM 00460 // Hmm, at least for Novell NetWare __dest_os == __mac_os true too.. 00461 // May be both __dest_os and __mac_os defined and empty? - ptr 00462 # if __dest_os == __mac_os 00463 inline int _FILE_fd(const FILE *__f) { return ::fileno(__CONST_CAST(FILE*, __f)); } 00464 # else 00465 inline int _FILE_fd(const FILE *__f) { return ::_fileno(__CONST_CAST(FILE*, __f)); } 00466 # endif // __dest_os == __mac_os 00467 00468 // Returns a pointer to the beginning of the buffer. 00469 inline char* _FILE_I_begin(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->buffer); } 00470 // Returns the current read/write position within the buffer. 00471 inline char* _FILE_I_next(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->buffer_ptr); } 00472 00473 // Returns a pointer immediately past the end of the buffer. 00474 inline char* _FILE_I_end(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->buffer_ptr + __f->buffer_len); } 00475 00476 // Returns the number of characters remaining in the buffer, i.e. 00477 // _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f). 00478 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->buffer_len; } 00479 00480 // Increments the current read/write position by 1, returning the 00481 // character at the old position. 00482 inline char& _FILE_I_preincr(FILE *__f) 00483 { --__f->buffer_len; return *(char*) (++__f->buffer_ptr); } 00484 inline char& _FILE_I_postincr(FILE *__f) 00485 { --__f->buffer_len; return *(char*) (__f->buffer_ptr++); } 00486 inline char& _FILE_I_predecr(FILE *__f) 00487 { ++__f->buffer_len; return *(char*) (--__f->buffer_ptr); } 00488 inline char& _FILE_I_postdecr(FILE *__f) 00489 { ++__f->buffer_len; return *(char*) (__f->buffer_ptr--); } 00490 inline void _FILE_I_bump(FILE *__f, int __n) 00491 { __f->buffer_ptr += __n; __f->buffer_len -= __n; } 00492 00493 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00494 __f->buffer = __REINTERPRET_CAST(unsigned char*, __begin); 00495 __f->buffer_ptr = __REINTERPRET_CAST(unsigned char*, __next); 00496 __f->buffer_len = __end - __next; 00497 __f->buffer_size = __end - __begin; 00498 } 00499 #else // N_PLAT_NLM - ptr 00500 inline int _FILE_fd(const FILE *__f) { return __f->_file; } 00501 inline char* _FILE_I_begin(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_base); } 00502 // Returns the current read/write position within the buffer. 00503 inline char* _FILE_I_next(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_ptr); } 00504 00505 // Returns a pointer immediately past the end of the buffer. 00506 inline char* _FILE_I_end(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_ptr + __f->_avail); } 00507 00508 // Returns the number of characters remaining in the buffer, i.e. 00509 // _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f). 00510 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_avail; } 00511 00512 // Increments the current read/write position by 1, returning the 00513 // character at the old position. 00514 inline char& _FILE_I_preincr(FILE *__f) 00515 { --__f->_avail; return *(char*) (++__f->_ptr); } 00516 inline char& _FILE_I_postincr(FILE *__f) 00517 { --__f->_avail; return *(char*) (__f->_ptr++); } 00518 inline char& _FILE_I_predecr(FILE *__f) 00519 { ++__f->_avail; return *(char*) (--__f->_ptr); } 00520 inline char& _FILE_I_postdecr(FILE *__f) 00521 { ++__f->_avail; return *(char*) (__f->_ptr--); } 00522 inline void _FILE_I_bump(FILE *__f, int __n) 00523 { __f->_ptr += __n; __f->_avail -= __n; } 00524 00525 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00526 __f->_base = __REINTERPRET_CAST(unsigned char*, __begin); 00527 __f->_ptr = __REINTERPRET_CAST(unsigned char*, __next); 00528 __f->_avail = __end - __next; 00529 } 00530 #endif // N_PLAT_NLM 00531 00532 00533 # define _STLP_FILE_I_O_IDENTICAL 00534 00535 #elif defined(__DMC__) 00536 00537 inline int _FILE_fd(const FILE *__f) { return __f->_file; } 00538 00539 // Returns a pointer to the beginning of the buffer. 00540 inline char* _FILE_I_begin(const FILE *__f) { return __f->_base; } 00541 00542 // Returns the current read/write position within the buffer. 00543 inline char* _FILE_I_next(const FILE *__f) { return __f->_ptr; } 00544 00545 // Returns a pointer immediately past the end of the buffer. 00546 inline char* _FILE_I_end(const FILE *__f) { return __f->_ptr + __f->_cnt; } 00547 00548 // Returns the number of characters remaining in the buffer, i.e. 00549 // _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f). 00550 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; } 00551 00552 // Increments the current read/write position by 1, returning the 00553 // character at the NEW position. 00554 inline char& _FILE_I_preincr(FILE *__f) { --__f->_cnt; return *(++__f->_ptr); } 00555 00556 00557 // Increments the current read/write position by 1, returning the 00558 // character at the old position. 00559 inline char& _FILE_I_postincr(FILE *__f) { --__f->_cnt; return *(__f->_ptr++); } 00560 00561 // Decrements the current read/write position by 1, returning the 00562 // character at the NEW position. 00563 inline char& _FILE_I_predecr(FILE *__f) { ++__f->_cnt; return *(--__f->_ptr); } 00564 00565 // Decrements the current read/write position by 1, returning the 00566 // character at the old position. 00567 inline char& _FILE_I_postdecr(FILE *__f) { ++__f->_cnt; return *(__f->_ptr--); } 00568 00569 // Increments the current read/write position by __n. 00570 inline void _FILE_I_bump(FILE *__f, int __n) { __f->_cnt -= __n; __f->_ptr += __n; } 00571 00572 // Sets the beginning of the bufer to __begin, the current read/write 00573 // position to __next, and the buffer's past-the-end pointer to __end. 00574 // If any of those pointers is null, then all of them must be null. 00575 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) 00576 { 00577 __f->_base = __begin; 00578 __f->_ptr = __next; 00579 __f->_cnt = __end - __next; 00580 __f->_bufsiz = __end - __begin; 00581 } 00582 00583 # define _STLP_FILE_I_O_IDENTICAL 00584 00585 #elif defined(__MRC__) || defined(__SC__) //*TY 02/24/2000 - added support for MPW 00586 00587 inline int _FILE_fd(const FILE *__f) { return __f->_file; } 00588 00589 // Returns a pointer to the beginning of the buffer. 00590 inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_base; } 00591 00592 // Returns the current read/write position within the buffer. 00593 inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_ptr; } 00594 00595 // Returns a pointer immediately past the end of the buffer. 00596 inline char* _FILE_I_end(const FILE *__f) { return (char*)__f->_end; } 00597 00598 // Returns the number of characters remaining in the buffer, i.e. 00599 // _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f). 00600 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; } 00601 00602 // Increments the current read/write position by 1, returning the 00603 // character at the NEW position. 00604 inline char& _FILE_I_preincr(FILE *__f) { --__f->_cnt; return*(char*) (++__f->_ptr); } 00605 00606 00607 // Increments the current read/write position by 1, returning the 00608 // character at the old position. 00609 inline char& _FILE_I_postincr(FILE *__f) { --__f->_cnt; return*(char*) (__f->_ptr++); } 00610 00611 // Decrements the current read/write position by 1, returning the 00612 // character at the NEW position. 00613 inline char& _FILE_I_predecr(FILE *__f) { ++__f->_cnt; return*(char*) (--__f->_ptr); } 00614 00615 // Decrements the current read/write position by 1, returning the 00616 // character at the old position. 00617 inline char& _FILE_I_postdecr(FILE *__f) { ++__f->_cnt; return*(char*) (__f->_ptr--); } 00618 00619 // Increments the current read/write position by __n. 00620 inline void _FILE_I_bump(FILE *__f, int __n) { __f->_cnt -= __n; __f->_ptr += __n; } 00621 00622 // Sets the beginning of the bufer to __begin, the current read/write 00623 // position to __next, and the buffer's past-the-end pointer to __end. 00624 // If any of those pointers is null, then all of them must be null. 00625 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) 00626 { 00627 __f->_base = (unsigned char*)__begin; 00628 __f->_ptr = (unsigned char*)__next; 00629 __f->_end = (unsigned char*)__end; 00630 __f->_cnt = __end - __next; 00631 __f->_size = __end - __begin; 00632 } 00633 00634 # define _STLP_FILE_I_O_IDENTICAL 00635 00636 #elif defined (__MVS__) 00637 00638 typedef unsigned char* _File_ptr_type; 00639 00640 inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE 00641 *,__f)); } 00642 inline char* _FILE_I_begin(const FILE *__f) { return (char*) 00643 __f->__fp->__bufPtr; } 00644 inline char* _FILE_I_next(const FILE *__f) { return (char*) 00645 __f->__fp->__bufPtr; } 00646 inline char* _FILE_I_end(const FILE *__f) 00647 { return (char*) __f->__fp->__bufPtr + __f->__fp->__countIn; } 00648 00649 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return 00650 __f->__fp->__countIn; } 00651 00652 inline char& _FILE_I_preincr(FILE *__f) 00653 { --__f->__fp->__countIn; return *(char*) (++__f->__fp->__bufPtr); } 00654 inline char& _FILE_I_postincr(FILE *__f) 00655 { --__f->__fp->__countIn; return *(char*) (__f->__fp->__bufPtr++); } 00656 inline char& _FILE_I_predecr(FILE *__f) 00657 { ++__f->__fp->__countIn; return *(char*) (--__f->__fp->__bufPtr); } 00658 inline char& _FILE_I_postdecr(FILE *__f) 00659 { ++__f->__fp->__countIn; return *(char*) (__f->__fp->__bufPtr--); } 00660 inline void _FILE_I_bump(FILE *__f, int __n) 00661 { __f->__fp->__bufPtr += __n; __f->__fp->__countIn -= __n; } 00662 00663 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* 00664 __end) { 00665 // __f->_base = (_File_ptr_type) __begin; 00666 if(__f->__fp) { 00667 __f->__fp->__bufPtr = (_File_ptr_type) __next; 00668 __f->__fp->__countIn = __end - __next; 00669 } 00670 } 00671 00672 inline char* _FILE_O_begin(const FILE *__f) { return (char*)__f->__fp->__bufPtr;} 00673 inline char* _FILE_O_next(const FILE *__f) { return (char*) __f->__fp->__bufPtr;} 00674 inline char* _FILE_O_end(const FILE *__f) { return (char*) __f->__fp->__bufPtr + __f->__fp->__countOut; } 00675 inline ptrdiff_t _FILE_O_avail(const FILE *__f) { return __f->__fp->__countOut; } 00676 00677 inline char& _FILE_O_preincr(FILE *__f) 00678 { --__f->__fp->__countOut; return *(char*) (++__f->__fp->__bufPtr); } 00679 inline char& _FILE_O_postincr(FILE *__f) 00680 { --__f->__fp->__countOut; return *(char*) (__f->__fp->__bufPtr++); } 00681 inline char& _FILE_O_predecr(FILE *__f) 00682 { ++__f->__fp->__countOut; return *(char*) (--__f->__fp->__bufPtr); } 00683 inline char& _FILE_O_postdecr(FILE *__f) 00684 { ++__f->__fp->__countOut; return *(char*) (__f->__fp->__bufPtr--); } 00685 inline void _FILE_O_bump(FILE *__f, int __n) 00686 { __f->__fp->__bufPtr += __n; __f->__fp->__countOut -= __n; } 00687 00688 inline void _FILE_O_set(FILE *__f, char* __begin, char* __next, char* 00689 __end) { 00690 // __f->_base = (_File_ptr_type) __begin; 00691 if(__f->__fp) { 00692 __f->__fp->__bufPtr = (_File_ptr_type) __next; 00693 __f->__fp->__countOut = __end - __next; 00694 } 00695 } 00696 00697 #elif defined(__QNXNTO__) 00698 00699 inline int _FILE_fd(const FILE *__f) { return __f->_handle; 00700 } 00701 inline char* _FILE_I_begin(const FILE *__f) { return 00702 (char*) __f->_base; } 00703 inline char* _FILE_I_next(const FILE *__f) { return 00704 (char*) __f->_ptr; } 00705 inline char* _FILE_I_end(const FILE *__f) 00706 { return (char*) __f->_ptr + __f->_cnt; } 00707 00708 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return 00709 __f->_cnt; } 00710 00711 inline char& _FILE_I_preincr(FILE *__f) 00712 { --__f->_cnt; return *(char*) (++__f->_ptr); } 00713 inline char& _FILE_I_postincr(FILE *__f) 00714 { --__f->_cnt; return *(char*) (__f->_ptr++); } 00715 inline char& _FILE_I_predecr(FILE *__f) 00716 { ++__f->_cnt; return *(char*) (--__f->_ptr); } 00717 inline char& _FILE_I_postdecr(FILE *__f) 00718 { ++__f->_cnt; return *(char*) (__f->_ptr--); } 00719 inline void _FILE_I_bump(FILE *__f, int __n) 00720 { __f->_ptr += __n; __f->_cnt -= __n; } 00721 00722 inline void _FILE_I_set(FILE *__f, char* __begin, char* 00723 __next, char* 00724 __end) { 00725 __f->_base = (unsigned char*) __begin; 00726 __f->_ptr = (unsigned char*) __next; 00727 __f->_cnt = __end - __next; 00728 } 00729 00730 # define _STLP_FILE_I_O_IDENTICAL 00731 00732 #elif defined(__WATCOMC__) // Nikolaev 00733 00734 inline int _FILE_fd (const FILE *__f) { return __f->_handle;} 00735 inline char* _FILE_I_begin (const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_link); } 00736 inline char* _FILE_I_next (const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_ptr); } 00737 inline char* _FILE_I_end (const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_ptr + __f->_cnt); } 00738 inline ptrdiff_t _FILE_I_avail (const FILE *__f) { return __f->_cnt; } 00739 00740 inline char& _FILE_I_preincr(FILE *__f) 00741 { 00742 --__f->_cnt; 00743 return *__REINTERPRET_CAST(char*, ++__f->_ptr); 00744 } 00745 00746 inline char& _FILE_I_postincr(FILE *__f) 00747 { 00748 --__f->_cnt; 00749 return *__REINTERPRET_CAST(char*, __f->_ptr++); 00750 } 00751 00752 inline char& _FILE_I_predecr(FILE *__f) 00753 { 00754 ++__f->_cnt; 00755 return *__REINTERPRET_CAST(char*, --__f->_ptr); 00756 } 00757 00758 inline char& _FILE_I_postdecr(FILE *__f) 00759 { 00760 ++__f->_cnt; 00761 return *__REINTERPRET_CAST(char*, __f->_ptr--); 00762 } 00763 00764 inline void _FILE_I_bump(FILE *__f, int __n) 00765 { 00766 __f->_ptr += __n; 00767 __f->_cnt -= __n; 00768 } 00769 00770 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) 00771 { 00772 __f->_link = __REINTERPRET_CAST(__stream_link*, __begin); 00773 __f->_ptr = __REINTERPRET_CAST(unsigned char*, __next); 00774 __f->_cnt = __end - __next; 00775 } 00776 00777 # define _STLP_FILE_I_O_IDENTICAL 00778 00779 #elif defined (__Lynx__) 00780 00781 // the prototypes are taken from LynxOS patch for STLport 4.0 00782 inline int _FILE_fd(const FILE *__f) { return __f->_fd; } 00783 inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_base; } 00784 inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_ptr; } 00785 inline char* _FILE_I_end(const FILE *__f) 00786 { return (char*) __f->_ptr + __f->_cnt; } 00787 00788 inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; } 00789 00790 inline char& _FILE_I_preincr(FILE *__f) 00791 { --__f->_cnt; return *(char*) (++__f->_ptr); } 00792 inline char& _FILE_I_postincr(FILE *__f) 00793 { --__f->_cnt; return *(char*) (__f->_ptr++); } 00794 inline char& _FILE_I_predecr(FILE *__f) 00795 { ++__f->_cnt; return *(char*) (--__f->_ptr); } 00796 inline char& _FILE_I_postdecr(FILE *__f) 00797 { ++__f->_cnt; return *(char*) (__f->_ptr--); } 00798 inline void _FILE_I_bump(FILE *__f, int __n) 00799 { __f->_ptr += __n; __f->_cnt -= __n; } 00800 00801 inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) { 00802 __f->_base = __begin; 00803 __f->_ptr = __next; 00804 __f->_cnt = __end - __next; 00805 } 00806 # define _STLP_FILE_I_O_IDENTICAL 00807 00808 #else /* A C library that we don't have an implementation for. */ 00809 00810 # error The C++ I/O library is not configured for this compiler 00811 00812 #endif 00813 00814 00815 // For most stdio's , input and output FILE manipulation is identical. 00816 # ifdef _STLP_FILE_I_O_IDENTICAL 00817 inline char* _FILE_O_begin(const FILE *__f) { return _FILE_I_begin(__f); } 00818 inline char* _FILE_O_next(const FILE *__f) { return _FILE_I_next(__f); } 00819 inline char* _FILE_O_end(const FILE *__f) { return _FILE_I_end(__f); } 00820 00821 inline ptrdiff_t _FILE_O_avail(const FILE *__f) { return _FILE_I_avail(__f); } 00822 00823 inline char& _FILE_O_preincr(FILE *__f) { return _FILE_I_preincr(__f); } 00824 inline char& _FILE_O_postincr(FILE *__f) { return _FILE_I_postincr(__f); } 00825 inline char& _FILE_O_predecr(FILE *__f) { return _FILE_I_predecr(__f); } 00826 inline char& _FILE_O_postdecr(FILE *__f) { return _FILE_I_postdecr(__f); } 00827 00828 inline void _FILE_O_bump(FILE *__f, int __n) { _FILE_I_bump(__f, __n); } 00829 inline void _FILE_O_set(FILE *__f, char* __begin, char* __next, char* __end) 00830 { _FILE_I_set(__f, __begin, __next, __end); } 00831 # endif 00832 00833 _STLP_END_NAMESPACE 00834 00835 #endif /* _STLP_STDIO_FILE_H */ 00836 00837 // Local Variables: 00838 // mode:C++ 00839 // End:
Generated on Mon Mar 10 15:32:15 2008 by ![]() |