VError OpenHelper::Open(const PathBuffer& inPath, FileDescSystemRef* outFd) { if(GetFileAccess()==FA_MAX) return OpenMax(inPath.GetPath(), outFd); bool failToGetLock=false; //(we don't care) VError verr=OpenStd(inPath.GetPath(), outFd, &failToGetLock); return verr; }
ReaddirHelper::ReaddirHelper(const PathBuffer& inFolderPath, FileIteratorOptions inOptions) : fOpts(inOptions), fDir(NULL), fPath(inFolderPath) { memset(&fEntry, 0, sizeof(fEntry)); //If it fails for any reason (inFolderPath is a file for ex.), opendir returns NULL. fDir=opendir(inFolderPath.GetPath()); }
VError MkdirHelper::MakeDir(const PathBuffer& inPath) const { mode_t modeFlags=PERM_755; int res=mkdir(inPath.GetPath(), modeFlags); return (res==0) ? VE_OK : MAKE_NATIVE_VERROR(errno); }
//static bool OpenHelper::ProcessCanWrite(const PathBuffer& inPath) { int fd=open(const_cast<char*>(inPath.GetPath()), O_WRONLY); if(fd>0) { close(fd); return true; } return false; }
VError StatHelper::Stat(const PathBuffer& inPath) { int res=(fFlags&followLinks) ? stat(inPath.GetPath(), &fStat) : lstat(inPath.GetPath(), &fStat); if(res==ENOENT || res==ENOTDIR) fDoesNotExist=true; //We are sure that the file doesn't exists if(res!=0) return MAKE_NATIVE_VERROR(errno); fDoesExist=true; //We are sure that the file exists if(fFlags&withFileSystemStats) { //I put stats on file systems here because they are obtained through a file of the fs. res=statfs(inPath.GetPath(), &fFsStat); if(res!=0) return MAKE_NATIVE_VERROR(errno); } return VE_OK; }
VError TouchHelper::Touch(const PathBuffer& inPath, VTime inAccessTime, VTime inModificationTime) const { struct utimbuf buf; memset(&buf, 0, sizeof(buf)); buf.actime=XBoxToUnixTime(inAccessTime); buf.modtime=XBoxToUnixTime(inModificationTime); int res=utime(inPath.GetPath(), &buf); if(res<0) return MAKE_NATIVE_VERROR(errno); return VE_OK; }
VError DynLoadHelper::Open(const PathBuffer& inLibPath) { fHandle=dlopen(inLibPath.GetPath(), fRelocationMode|fScopeMode); if(fHandle==NULL) { char* msg=dlerror(); if(msg!=NULL) DebugMsg("dlopen error %s\n", msg); return VE_INVALID_PARAMETER; } return VE_OK; }
VError CreateHelper::Create(const PathBuffer& inPath) const { //I'm pretty sure it doesn't behave in the same way than the windows platform. //(the share and overwrite behavior might be different) int openFlags=0; if(fCreateOpts & FCR_Overwrite) openFlags|=O_RDONLY|O_CREAT; //CREATE_ALWAYS ? else openFlags|=O_RDONLY|O_CREAT|O_EXCL; //CREATE_NEW mode_t modeFlags=PERM_644; int fd=open(const_cast<char*>(inPath.GetPath()), openFlags, modeFlags); if(fd<0) return MAKE_NATIVE_VERROR(errno); close(fd); return VE_OK; }
VError RenameHelper::Rename(const PathBuffer& inSrc, const PathBuffer& inDst) const { int res=rename(inSrc.GetPath(), inDst.GetPath()); return (res==0) ? VE_OK : MAKE_NATIVE_VERROR(errno); }
VError LinkHelper::Link(const PathBuffer& inLinkPath, const PathBuffer &inTargetPath) const { int res=symlink(inTargetPath.GetPath(), inLinkPath.GetPath()); return (res==0) ? VE_OK : MAKE_NATIVE_VERROR(errno); }
bool StatHelper::Access(const PathBuffer& inPath) { int res=access(inPath.GetPath(), F_OK); return (res==0) ? true : false ; };
VError RemoveHelper::Remove(const PathBuffer& inPath) { int res=unlink(inPath.GetPath()); return (res==0) ? VE_OK : MAKE_NATIVE_VERROR(errno); }
VError RmdirHelper::RemoveDir(const PathBuffer& inPath) const { int res=rmdir(inPath.GetPath()); return (res==0) ? VE_OK : MAKE_NATIVE_VERROR(errno); }