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

📄 wysysfile.h

📁 一个不错
💻 H
字号:
/* Copyright is licensed under GNU LGPL.                 by I.J.Wang 2005   Documentation in file wysysfile.3wy*/#ifndef WYSYSFILE_H__#define WYSYSFILE_H__#define WYSYSFILE_VERSION 31#include "wystr.h"#include "wyfilehandle.h"#include "wy__cfunc.h"   // for Wy::_delete..#include <fcntl.h>       // for symbols (e.g. O_RDONLY..)#include <sys/types.h>   // for symbols#include <sys/stat.h>    // manual says (mode_t probably)#ifdef WY_DEBUG#include <pthread.h>#endifclass Wy__FtBits {    mode_t _bts;    Wy__FtBits(const Wy__FtBits& b1, const Wy__FtBits& b2)          : _bts(b1._bts|b2._bts) {};  public:    // [Syn] Construct object from system file type mode_t to Wy__FtBits    //    // Note: The argument m is supposed to be exactly the value equal to the    //       the symbols S_IFREG, S_IFCHR, S_IFSOCK, S_IFIFO, S_IFDIR, S_IFLNK    //       ,and S_IFBLK.    //    Wy__FtBits(mode_t m) WY__NOTHROW__;    Wy__FtBits(const Wy__FtBits& src) WY__NOTHROW__ : _bts(src._bts) {};    bool is_joint(const Wy__FtBits& src) const WY__NOTHROW__         { return _bts&src._bts; };    Wy__FtBits operator+ (const Wy__FtBits& src) const WY__NOTHROW__         { return Wy__FtBits(*this,src); };};class WySysFile {    static const Wy__TypeFD DefaultFd=WY__DEFAULT_FD;    static const mode_t DefaultFType=0;    static Wy__FtBits cftbits(void) WY__NOTHROW__; // Wy__FtBits for this class    #ifdef WY_DEBUG    static int _dbg_objcnt;   // for tracking number of objects    static ::pthread_mutex_t _dbg_mtx;    #endif    // [Internal] Overwrite this->_m_fd to be exactly the given fd    //            This member is dedicated for Wy__Std implement    //    //   --Warning--     //   Function overwrites fd, make sure no resource is lost, and file type    //   of fd is suitable for the class. And note the rule for ftype.    //    //  Note: This member is dedicated for WyByteFlow to initialize objects    //        for standard devices.     //    void _overwrite(Wy__TypeFD fd, mode_t ftype) WY__NOTHROW__;    // [Cancel Point]    //    // [Syn] Open (::open) a file descriptor and overwite _m_fd/_m_ftype    //    // [Throw] Reply    //         Wym_EFAULT      pathname pointed address is inaccessible    //         Wym_EBADF       file not valid for the operation    //         Wym_EACCES      Search permission is denied    //         Wym_EINVAL      \fIf\fP invalid    //         Wym_ENAMETOOLONG \fIpathname\fP too long    //         Wym_ENOENT      \fIpathname\fP does not exist    //         Wym_ENOTDIR     Entry in \fIpathname\fP is not a directory    //         Wym_EMFILE      Too many open fd    //         Wym_ENFILE      File table overflow    //         Wym_ENOMEM      Not enough memory    //         Wym_EEXIST      Pathname already exists    //         Wym_EINTR       Interrupted by a signal    //         Wym_ENOSPC      Device left no space for the operation    //         Wym_ENXIO       No such device (device not ready)    //         Wym_EROFS       Read-only file system    //         Wym_ENODEV      No such device    //         Wym_ELOOP       Too many symbolic links encountered    //         ...             reply converted from ::open    //    // [Refer] ::open(const char*,int)    //    inline void _init(const char* pathname,int flags);    const Wy__FtBits _cif;    Wy__TypeFD _m_fd;      // File descriptor    // [Syn] Actual file type of _m_fd    //    //       0        default    //       S_IFREG  regular file    //       S_IFCHR  character device    //       S_IFSOCK socket    //       S_IFIFO  fifo    //       S_IFDIR  directory file    //       S_IFLNK  symbolic link    //       S_IFBLK  block device    //    mode_t     _m_ftype;    // Hidden    const WySysFile& operator=(const WySysFile& rhs);    bool operator==(const WySysFile& rhs) const;    bool operator!=(const WySysFile& rhs) const;     protected:    // note: These members are not public because implement does not know    //       what the pathname is really meant (e.g. lnk).    //    WySysFile(const char* pathname,int f,const Wy__FtBits cif=cftbits());    WySysFile(const WyStr& pathname,int f,const Wy__FtBits cif=cftbits());    virtual WyRet reset(const char* pathname, int flags);    virtual WyRet reset(const WyStr& pathname, int flags);  public:    static const char class_name[];    WY_THROW_REPLY;    // [Throw] Reply    //         reserved    //    explicit  // no implicit conversion    WySysFile(const Wy__FtBits cif=cftbits());    // [Throw] Reply    //         Wym_EBADF   \fIfh\fP not valid for the operation    //         Wym_EMFILE  too many open devices    //         Wym_ENOMEM  Not enough memory    //    // [Refer] ::dup(int)    //    WySysFile(WyFileHandle fh, const Wy__FtBits cif=cftbits());    // [Throw] Reply    //         error from ::dup(int)    //    // [Refer] ::dup(int)    //    WySysFile(const WySysFile& sysf, const Wy__FtBits cif=cftbits());    // [Move Constructor]    //    // Note: sysf must be whole object except in initialization list    //    WySysFile(WySysFile& sysf,Wy::ByMove_t) WY__TSPC();    // Note: Not Cancellable    //     virtual ~WySysFile();    bool is_default(void) const WY__TSPC();    WyFileHandle fh(void) const WY__TSPC();    mode_t ftype(void) const WY__TSPC();    WyRet stat(WyFileStat& filestat) const;    // [Cancel Point]    //    virtual WyRet reset(void);    virtual WyRet reset(WyFileHandle fh);    virtual WyRet reset(const WySysFile& sysf);    virtual WyRet _swap(WySysFile& sysf) WY__TSPC();    virtual WySysFile* _alloc(WyRet&) const;    // [Cancel Point]    //    // [Syn] Close the file descriptor    //    // [Ret] 0     Ok    //       EBADF fd is not a valid open fd    //       EINTR interrupted by a signal (fd is closed)    //       EIO   I/O error    //    // [Refer] ::close(int)    //    static int wy_close(const Wy__TypeFD& fd);    Wy__TypeFD wy_fd(void) const WY__NOTHROW__         { return _m_fd; };    #ifdef WY_DEBUG    static int wydbg_get_objcnt(void) throw();    static void wydbg_dec_objcnt(void) throw();    static void wydbg_inc_objcnt(void) throw();    #endif    friend class Wy__Std;    // Wy__Std accesses _cif directly, and _overwrite    // The chk file will access protected ctor/reset(..)..    friend void ck_sysfile_1(void);    friend void ck_byteflow_1(void);};#endif

⌨️ 快捷键说明

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