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

📄 wyfilehandle.cpp

📁 一个不错
💻 CPP
字号:
#define WYLIB_SOURCE#include "wyfilehandle.h"#include "wy__cfunc.h"#include "wy_atdestroy.h"#include <unistd.h>      // access,chdir,stat,link...#include <sys/select.h>  // for FD_SETSIZE#include <cstdlib>#include <new>  // for bad_allocconst char WyFileHandle::class_name[]="WyFileHandle";class WyFileHandle::Assertion {  public:    Assertion()      {        if(WY__DEFAULT_FD!=-1) {          WY_TERMINATE("");  // default fd is hard-coded as -1                        // range of fd= [-1,wy_MaxFd]        }      };} static const wy__do_not_use_me__;WyRet WyFileHandle::stat(WyFileStat& filestat) const{ // Assert that ::fstat failure should not modify buf. // if(wyc_fstat(_fd,filestat.wy_stat_ptr())==-1) {   WY_RETURN(errno); } return(Ok);};namespace Wy {WyRet unlink(const WyStr& pathname){ if(::unlink(pathname.c_str())!=0) {   WY_RETURN(errno); } return(Ok);};WyRet unlink(const char* pathname){ if(::unlink(pathname)!=0) {   WY_RETURN(errno); } return(Ok);};WyRet access(const WyStr& pathname,int mode){ if(::access(pathname.c_str(),mode)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet access(const char* pathname,int mode){ if(::access(pathname,mode)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet chdir(const WyStr& path){ if(::chdir(path.c_str())!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet chdir(const char* path){ if(::chdir(path)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet getcwd(WyStr& path)try { for(size_t bsize=256; bsize<=Wy::_MaxPathSize+256; bsize+=256) {   char* buf=(char*)std::malloc(bsize);   if(buf==0) {     WY_RETURN(Wym_ENOMEM);   }   Wy_AtDestroy<void,char*> rrid(reinterpret_cast<void(*)(char*)>(&std::free), buf);   if(::getcwd(buf,bsize)== buf) {     const WyRet r=path.reset( WyCSeg(buf) );     if(r!=Ok) {       WY_RETURN(r);     }     return(Ok);   }   const int v=errno;   if(v==ERANGE) {     continue;   }   WY_RETURN(WyReply(v)); } WY_RETURN(Wym_ENAMETOOLONG);}catch(const WyRet& e) {  WY_THROW( WyRet(e) );};WyRet chown(const WyStr& path,uid_t owner,gid_t group){ if(::chown(path.c_str(),owner,group)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet chown(const char* path,uid_t owner,gid_t group){ if(::chown(path,owner,group)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet chmod(const WyStr& path,mode_t mode){ if(::chmod(path.c_str(),mode)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet chmod(const char* path,mode_t mode){ if(::chmod(path,mode)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet link(const WyStr& oldpath,const WyStr& newpath){  if(::link(oldpath.c_str(),newpath.c_str())!=0) {    WY_RETURN(errno);  }  return(Ok);};WyRet link(const char* oldpath,const char* newpath){  if(::link(oldpath,newpath)!=0) {    WY_RETURN(errno);  }  return(Ok);};};

⌨️ 快捷键说明

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