📄 _stdio_file.h
字号:
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_STDIO_FILE_H
#define _STLP_STDIO_FILE_H
// This file provides a low-level interface between the internal
// representation of struct FILE, from the C stdio library, and
// the C++ I/O library. The C++ I/O library views a FILE object as
// a collection of three pointers: the beginning of the buffer, the
// current read/write position, and the end of the buffer.
// The interface:
// - char* _FILE_[IO]_begin(const FILE *__f);
// Returns a pointer to the beginning of the buffer.
// - char* _FILE_[IO]_next(const FILE *__f);
// Returns the current read/write position within the buffer.
// - char* _FILE_[IO]_end(const FILE *__f);
// Returns a pointer immediately past the end of the buffer.
// - char* _FILE_[IO]_avail(const FILE *__f);
// Returns the number of characters remaining in the buffer, i.e.
// _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f).
// - char& _FILE_[IO]_preincr(FILE *__f)
// Increments the current read/write position by 1, returning the
// character at the old position.
// - char& _FILE_[IO]_postincr(FILE *__f)
// Increments the current read/write position by 1, returning the
// character at the old position.
// - char& _FILE_[IO]_predecr(FILE *__f)
// Decrements the current read/write position by 1, returning the
// character at the old position.
// - char& _FILE_[IO]_postdecr(FILE *__f)
// Decrements the current read/write position by 1, returning the
// character at the old position.
// - void _FILE_[IO]_bump(FILE *__f, int __n)
// Increments the current read/write position by __n.
// - void _FILE_[IO]_set(FILE *__f, char* __begin, char* __next, char* __end);
// Sets the beginning of the bufer to __begin, the current read/write
// position to __next, and the buffer's past-the-end pointer to __end.
// If any of those pointers is null, then all of them must be null.
// Each function comes in two versions, one for a FILE used as an input
// buffer and one for a FILE used as an output buffer. In some stdio
// implementations the two functions are identical, but in others they are
// not.
#ifndef _STLP_CSTDIO
# include <cstdio>
#endif
#ifndef _STLP_CSTDDEF
# include <cstddef>
#endif
#if defined(__MSL__) && !defined(N_PLAT_NLM)
# include <unix.h> // get the definition of fileno
#endif
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// Implementation for eMbedded Visual C++ 3.0 and 4.2 (.NET)
#if defined (_STLP_WCE)
inline int _FILE_fd(const FILE *__f)
{
/* check if FILE is one of the three standard streams
We do this check first, because invoking _fileno() on one of them
causes a terminal window to be created. This also happens if you do
any IO on them, but merely retrieving the filedescriptor shouldn't
already do that.
Obviously this is pretty implementation-specific because it requires
that indeed the first three FDs are always the same, but that is not
only common but almost guaranteed. */
for( int __fd=0; __fd!=3; ++__fd)
{
if(__f == _getstdfilex(__fd))
return __fd;
}
return (int)::_fileno((FILE*)__f);
}
# undef _STLP_FILE_I_O_IDENTICAL
// Implementation for the IRIX C library.
// Solaris interface looks to be identical.
#elif !defined(_STLP_USE_GLIBC) && \
( defined(__sgi) || \
( defined(__sun) && ! defined (_LP64) ) || \
defined (__osf__) || defined(__DECCXX) || \
(defined (_STLP_MSVC) && !defined (_STLP_WCE_EVC3)) || \
defined (__ICL) || defined (__MINGW32__) || defined(__DJGPP) || defined (_AIX) || defined (_CRAY))
#if defined (_STLP_MSVC) || defined (__ICL) || defined (__MINGW32__) || defined(__DJGPP)
typedef char* _File_ptr_type;
#else
typedef unsigned char* _File_ptr_type;
#endif
inline int _FILE_fd(const FILE *__f) { return __f->_file; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_base; }
inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_ptr; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->_ptr + __f->_cnt; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->_cnt; return *(char*) (++__f->_ptr); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->_cnt; return *(char*) (__f->_ptr++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->_cnt; return *(char*) (--__f->_ptr); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->_cnt; return *(char*) (__f->_ptr--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->_ptr += __n; __f->_cnt -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) {
__f->_base = (_File_ptr_type) __begin;
__f->_ptr = (_File_ptr_type) __next;
__f->_cnt = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL 1
#elif defined(__EMX__)
inline int _FILE_fd(const FILE* __f) { return __f->_handle; }
inline char* _FILE_I_begin(const FILE* __f) { return (char*) __f->_buffer; }
inline char* _FILE_I_next(const FILE* __f) { return (char*) __f->_ptr; }
inline char* _FILE_I_end(const FILE* __f) { return (char *) __f->_ptr + __f->_rcount; }
inline ptrdiff_t _FILE_I_avail(const FILE* __f) { return __f->_rcount; }
inline char& _FILE_I_preincr(FILE* __f) { --__f->_rcount; return *(char*) (++__f->_ptr); }
inline char& _FILE_I_postincr(FILE* __f) { --__f->_rcount; return *(char*) (__f->_ptr++); }
inline char& _FILE_I_predecr(FILE* __f) { ++__f->_rcount; return *(char*) (--__f->_ptr); }
inline char& _FILE_I_postdecr(FILE* __f) { ++__f->_rcount; return *(char*) (__f->_ptr--); }
inline void _FILE_I_bump(FILE* __f, int __n) { __f->_ptr += __n; __f->_rcount -= __n; }
inline void _FILE_I_set(FILE* __f, char* __begin, char* __next, char* __end) {
__f->_buffer = __begin;
__f->_ptr = __next;
__f->_rcount = __end - __next;
}
inline char* _FILE_O_begin(const FILE* __f) { return (char*) __f->_buffer; }
inline char* _FILE_O_next(const FILE* __f) { return (char*) __f->_ptr; }
inline char* _FILE_O_end(const FILE* __f) { return (char*) __f->_ptr + __f->_wcount; }
inline ptrdiff_t _FILE_O_avail(const FILE* __f) { return __f->_wcount; }
inline char& _FILE_O_preincr(FILE* __f) { --__f->_wcount; return *(char*) (++__f->_ptr); }
inline char& _FILE_O_postincr(FILE* __f) { --__f->_wcount; return *(char*) (__f->_ptr++); }
inline char& _FILE_O_predecr(FILE* __f) { ++__f->_wcount; return *(char*) (--__f->_ptr); }
inline char& _FILE_O_postdecr(FILE* __f) { ++__f->_wcount; return *(char*) (__f->_ptr--); }
inline void _FILE_O_bump(FILE* __f, int __n) { __f->_ptr += __n; __f->_wcount -= __n; }
inline void _FILE_O_set(FILE* __f, char* __begin, char* __next, char* __end) {
__f->_buffer = __begin;
__f->_ptr = __next;
__f->_wcount = __end - __next;
}
# undef _STLP_FILE_I_O_IDENTICAL
# elif defined(_STLP_SCO_OPENSERVER) || defined(__NCR_SVR)
typedef unsigned char* _File_ptr_type;
inline int _FILE_fd(const FILE *__f) { return __f->__file; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->__base; }
inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->__ptr; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->__ptr + __f->__cnt; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->__cnt; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->__cnt; return *(char*) (++__f->__ptr); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->__cnt; return *(char*) (__f->__ptr++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->__cnt; return *(char*) (--__f->__ptr); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->__cnt; return *(char*) (__f->__ptr--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->__ptr += __n; __f->__cnt -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) {
__f->__base = (_File_ptr_type) __begin;
__f->__ptr = (_File_ptr_type) __next;
__f->__cnt = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL 1
# elif defined(__sun) && defined( _LP64)
typedef long _File_ptr_type;
inline int _FILE_fd(const FILE *__f) { return (int) __f->__pad[2]; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*)
__f->__pad[1]; }
inline char* _FILE_I_next(const FILE *__f) { return (char*)
__f->__pad[0]; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->__pad[0] + __f->__pad[3]; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->__pad[3]; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->__pad[3]; return *(char*) (++__f->__pad[0]); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->__pad[3]; return *(char*) (__f->__pad[0]++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->__pad[3]; return *(char*) (--__f->__pad[0]); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->__pad[3]; return *(char*) (__f->__pad[0]--); }
inline void _FILE_I_bump(FILE *__f, long __n)
{ __f->__pad[0] += __n; __f->__pad[3] -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char*
__end) {
__f->__pad[1] = (_File_ptr_type) __begin;
__f->__pad[0] = (_File_ptr_type) __next;
__f->__pad[3] = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL
#elif defined (__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \
|| defined(__amigaos__) || ( defined(__GNUC__) && defined(__APPLE__) )
inline int _FILE_fd(const FILE *__f) { return __f->_file; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_bf._base; }
inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_p; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->_p + __f->_r; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_r; }
#if ( defined(__GNUC__) && defined(__APPLE__) )
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->_r; return *(char*) (++__f->_p); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->_r; return *(char*) (__f->_p++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->_r; return *(char*) (--__f->_p); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->_r; return *(char*) (__f->_p--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->_p += __n; __f->_r -= __n; }
#else
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->_r; --__f->_bf._size; return *(char*) (++__f->_p); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->_r; --__f->_bf._size; return *(char*) (__f->_p++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->_r; ++ __f->_bf._size; return *(char*) (--__f->_p); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->_r; ++__f->_bf._size; return *(char*) (__f->_p--); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -