⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _file.h

📁 realview22.rar
💻 H
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
 *
 * _file.h - Wrapper definitions for platform independent file I/O
 *
 * This is an internal header file used to implement the C++ Standard
 * Library. It should never be #included directly by a program.
 *
 * $Id: _file.h,v 1.4 2003/03/31 08:44:35 wmunns Exp $
 *
 ***************************************************************************
 *
 * Copyright (c) 1994-2001 Rogue Wave Software, Inc.  All Rights Reserved.
 *
 * This computer software is owned by Rogue Wave Software, Inc. and is
 * protected by U.S. copyright laws and other laws and by international
 * treaties.  This computer software is furnished by Rogue Wave Software,
 * Inc. pursuant to a written license agreement and may be used, copied,
 * transmitted, and stored only in accordance with the terms of such
 * license and with the inclusion of the above copyright notice.  This
 * computer software or any other copies thereof may not be provided or
 * otherwise made available to any other person.
 *
 * U.S. Government Restricted Rights.  This computer software is provided
 * with Restricted Rights.  Use, duplication, or disclosure by the
 * Government is subject to restrictions as set forth in subparagraph (c)
 * (1) (ii) of The Rights in Technical Data and Computer Software clause
 * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
 * Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19,
 * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
 * Flatiron Parkway, Boulder, Colorado 80301 USA.
 *
 **************************************************************************/

#ifndef _RWSTD_FILE_H_INCLUDED
#define _RWSTD_FILE_H_INCLUDED

#include <rw/_defs.h>
#include _RWSTD_CSTDIO

#if (defined (_WIN32) || defined (_WIN64)) && !defined (__CYGWIN__)

#  include <io.h>

#  ifndef STDIN_FILENO
#    define STDIN_FILENO  0
#    define STDOUT_FILENO 1
#    define STDERR_FILENO 2
#  endif   // STDIN_FILENO

#else
#ifndef _RWSTD_NO_FILENO
#    include <unistd.h>
#else 
#    include <rw/_file_support.h>
#endif //_RWSTD_NO_FILENO
#endif   // _WIN32 || _WIN64

#ifndef _RWSTD_NO_FILENO
#include <fcntl.h>
#endif //_RWSTD_NO_FILENO

#if defined (_WIN32) || defined (_WIN64)
#  define _BINARY _O_BINARY
#else 
#  define _BINARY 0
#endif 


#if defined (__sun__) || defined (__sun) || defined (sun)

// fileno isn't available (e.g., for strict ANSI C conformance)
// this may result in a (hopefully) benign redeclaration
extern "C" int fileno (FILE*);

#endif   // __sun__

_RWSTD_NAMESPACE_BEGIN (__rw)

_USING (namespace std);


// __rw_file_t implements a file abstraction used by std::basic_filebuf<>
// the size of the object is guaranteed to be the same regardless
// of whether FILE* or int (for file descriptor) is used - switching
// between one and the other (for efficiency) is controlled via the
// macro _RWSTD_NO_NATIVE_IO

union _RWSTD_EXPORT __rw_file_t
{
private:

    static bool _C_is_open (FILE *__fp) {
        return  !(__fp == (FILE*)_RWSTD_INVALID_FILE_PTR);
    }

    static int _C_fileno (FILE *__fp) {
        return _C_is_open (__fp)
            ? fileno(__fp)
            : _RWSTD_INVALID_FILE_DESC;
    }

public:
    static int _C_get_mode (int);

    static int _C_get_mode (FILE *__fp);

#ifndef _RWSTD_NO_NATIVE_IO

    __rw_file_t ( ) : _C_fdsc (_RWSTD_INVALID_FILE_DESC)
        { }

    __rw_file_t (FILE *__fp) : _C_fdsc (_C_fileno (__fp))
        { }
    __rw_file_t (int __fd) : _C_fdsc (__fd)
        { }
    __rw_file_t (const __rw_file_t &__f) : _C_fdsc (__f._C_fdsc)
        { }

    __rw_file_t & operator= (const __rw_file_t &__f) {
        _C_fdsc = __f._C_fdsc;
        return *this;
    }
    
    int _C_get_mode () const;

    int _C_get_mode_arg (int) const;

    int _C_get_fd () const {
        return _C_fdsc;
    }

    bool _C_is_open () const {
        return  _C_fdsc != _RWSTD_INVALID_FILE_DESC;
    }

    bool _C_is_stdin () const {
        return STDIN_FILENO == _C_fdsc;
    }

    bool _C_is_stdout () const {
        return STDOUT_FILENO == _C_fdsc;
    }

    bool _C_is_stderr () const {
        return STDERR_FILENO == _C_fdsc;
    }

    bool _C_is_std () const {
        return _C_is_stdin () || _C_is_stdout () || _C_is_stderr ();
    }

    __rw_file_t& _C_open (const char *__name, int __mode, long __prot);

    bool _C_close () {
        return 0 == close (_C_fdsc);
    }

    size_t _C_read (void *__buf, size_t __size, size_t __count) {
        _RWSTD_SSIZE_T __nbytes = read (_C_fdsc, __buf, __size * __count);
        return __nbytes < 0 ? 0 : _RWSTD_STATIC_CAST (size_t, __nbytes);
    }

    bool _C_write (const void* __buf, size_t __size, size_t __count) {
        return (    (size_t)write (_C_fdsc, __buf, __size * __count)
                 == __size * __count);
    }

    long _C_seek (long __offset, int __origin) {
        return lseek (_C_fdsc, __offset, __origin);
    }

    // For non-native i/o facilitation only.
    int _C_flush ( ) {
        return 0;
    }

#else // if defined (_RWSTD_NO_NATIVE_IO)
    
    const char* _C_get_mode_arg (int) const;

    __rw_file_t ( ) : _C_fptr (0)
        { }

    __rw_file_t (FILE *__fp) : _C_fptr (__fp)
        { }

    __rw_file_t (int);

    __rw_file_t (const __rw_file_t &__f) : _C_fptr (__f._C_fptr)
        { }

    __rw_file_t& operator= (const __rw_file_t &__f) {
        _C_fptr = __f._C_fptr;
        return *this;
    }

    int _C_get_mode () const;

    int _C_get_fd () const {
        return _C_fileno (_C_fptr);
    }

    bool _C_is_open () const {
        return  !!_C_fptr;
    }

    bool _C_is_stdin () const {
        return STDOUT_FILENO ==_C_fileno (_C_fptr);
    }

    bool _C_is_stdout () const {
        return STDOUT_FILENO ==_C_fileno (_C_fptr);
    }

    bool _C_is_stderr () const {
        return STDERR_FILENO ==_C_fileno (_C_fptr);
    }
    
    bool _C_is_std () const {
        return _C_is_stdin () || _C_is_stdout () || _C_is_stderr ();
    }

    __rw_file_t &
    _C_open (const char *__name, int __mode, long);

    bool _C_close () {
        return !_C_is_open () ? true : 0 == fclose (_C_fptr);
    }

    size_t _C_read (void *__buf, size_t __size, size_t __count) {
#define __ARM_USE_FREAD_BYTES_AVAIL
#ifdef __ARM_USE_FREAD_BYTES_AVAIL
        size_t __bytes_read = __fread_bytes_avail(__buf, __size * __count, _C_fptr);
        /* fread can set a sticky EOF, clear it if there has been no error */
        if (!ferror(_C_fptr)) clearerr(_C_fptr);
        return __bytes_read;
#else
        return __size * fread (__buf, __size, __count, _C_fptr);
#endif
    }

    bool _C_write (const void* __buf, size_t __size, size_t __count) {
        return fwrite (__buf, __size, __count, _C_fptr) == __count;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -