📄 vfile.cpp
字号:
/*************************************************************************** vfile.cpp - description ------------------- begin : 2003.7.31 copyright : (C) 2003 by |LiuZhong| email : |zliu@foundermn.com| ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <string.h>#include "vfile.h"VFile::VFile(){ m_Vfp = NULL;}VFile::~VFile(){ Close();}bool VFile::Open(const char *path,const char *mode){ bool Val = false; Close(); m_Vfp = fopen(path,mode); if(m_Vfp){ Val = true; } return Val;}long VFile::Read(void* ptr,long size){ long count=0; if(m_Vfp){ count = fread(ptr,1,size,m_Vfp); } return count;}long VFile::Write(const void *ptr,long size){ long count=0; if(m_Vfp){ count = fwrite(ptr,1,size,m_Vfp); } return count;}long VFile::ReadLine(char* ptr,long size){ long count=0; if(m_Vfp){ memset(ptr,0,size); if(fgets(ptr,size,m_Vfp)){ count = strlen(ptr); } } return count;}long VFile::WriteLine(const char *ptr){ long count=0; if(m_Vfp){ count = fwrite(ptr,1,strlen(ptr),m_Vfp); } return count;}long VFile::Seek(long Offset,int Whence){ long pos = -1; if(m_Vfp){ fseek(m_Vfp,Offset,Whence); pos = ftell(m_Vfp); } return pos; }void VFile::Close(){ if(m_Vfp){ fclose(m_Vfp); m_Vfp = NULL; } }long VFile::Length(const char* FName){ struct stat sbuf; if(stat(FName,&sbuf)<0) return -1; else return sbuf.st_size;}bool VFile::DirExist(const char* Dir){ if(access(Dir,F_OK)<0) return false; else return true;}bool VFile::FileExist(const char* FName){ if(access(FName,F_OK)<0) return false; else return true;}bool VFile::Mkdir(const char* Dir){ if(mkdir(Dir,0755)<0) return false; else return true;}bool VFile::Rmdir(const char* Dir){ if(remove(Dir)<0) return false; else return true;}bool VFile::Remove(const char* FName){ if(remove(FName)<0) return false; else return true; }bool VFile::Rename(const char* oldname,const char* newname){ if(rename(oldname,newname)<0) return false; else return true;}long VFile::SetLength(const char* FName,long newlen) { if(truncate(FName,newlen)<0) return false; else return true;}bool VFile::CreatePath(const char* FilePath){ char dir[256]; memset(dir,0,256); for(int i=0;i<strlen(FilePath);i++){ dir[i] = FilePath[i]; if(dir[i]=='/' && i!=0){ if(!DirExist(dir)){ if(!Mkdir(dir)) return false; } } } return true;}bool VFile::SplitDirFile(const char* FilePath,char* Dir,char* File){ char *p = strrchr(FilePath,'/'); int Pos = (p)?p-(char*)FilePath:-1; if(Pos>=0){ strncpy(Dir,FilePath,Pos+1); *(Dir+Pos+1) = '\0'; strcpy(File,FilePath+Pos+1); return true; } return false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -