代码拉取完成,页面将自动刷新
同步操作将从 乏力大仙/CPP-SimpleWebServer 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#ifndef FILE_HANDLER
#define FILE_HANDLER
#include<string>
#include<unistd.h>
#include<sys/stat.h>
#include"Defines.cpp"
class FileHandler
{
private:
FILE* _file = NULL;
std::string _filePath;
public:
FileHandler(std::string path, std::string mode = "r")
{
_filePath = path;
//判断文件是否存在
if(IsFileExist() == false)
{
PrintLine("文件不存在 [%s]", _filePath.c_str());
return;
}
//打开文件
_file = fopen(_filePath.c_str(), mode.c_str());
if(_file == NULL)
{
PrintLine("文件打开失败 [%s]", _filePath.c_str());
return;
}
}
int Read(char *buff, int length)
{
int ret = fread(buff, sizeof(char), length, _file);
return ret;
}
long GetFileSize()
{
return GetFileSize(_filePath);
}
bool IsDirectoryFile()
{
return IsDirectoryFile(_filePath);
}
bool IsOrdinaryFile()
{
return IsOrdinaryFile(_filePath);
}
bool IsFileExist()
{
return IsFileExist(_filePath);
}
//静态函数
static long GetFileSize(std::string path)
{
FILE *file = fopen(path.c_str(), "r");
if(file == NULL)
{
PrintLine("文件指针为空 %s", path);
return -1;
}
fseek(file, 0L, SEEK_END);
long ret = ftell(file);
fclose(file);
return ret;
}
static bool IsDirectoryFile(std::string path)
{
struct stat st;
stat(path.c_str(), &st);
return S_ISDIR(st.st_mode);
}
static bool IsOrdinaryFile(std::string path)
{
struct stat st;
stat(path.c_str(), &st);
return S_ISREG(st.st_mode);
}
static bool IsFileExist(std::string path)
{
return access(path.c_str(), F_OK) == 0 && (IsOrdinaryFile(path) || IsDirectoryFile(path));
}
};
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。