mirror of
https://gitee.com/TarsCloud/TarsCpp.git
synced 2024-12-22 22:16:38 +08:00
fix tc_file load2file bug
This commit is contained in:
parent
12dd6bb40c
commit
26771398b7
2
unittest
2
unittest
@ -1 +1 @@
|
||||
Subproject commit 5f46a694b925be139aa16274a00b7d5ad611004c
|
||||
Subproject commit e663956b02aa72f9491f759263da89d62502f7e8
|
@ -231,20 +231,29 @@ string TC_File::simplifyDirectory(const string& path)
|
||||
|
||||
string TC_File::load2str(const string &sFullFileName)
|
||||
{
|
||||
int fd = open(sFullFileName.data(), O_RDONLY);
|
||||
if (fd < 0)
|
||||
return "";
|
||||
// int fd = open(sFullFileName.data(), O_RDONLY);
|
||||
// if (fd < 0)
|
||||
// return "";
|
||||
|
||||
string s = "";
|
||||
int nread = -1;
|
||||
do {
|
||||
char buf[1024] = {'\0'};
|
||||
nread = read(fd, buf, sizeof(buf));
|
||||
if (nread > 0)
|
||||
s += buf;
|
||||
} while (nread > 0);
|
||||
close(fd);
|
||||
return s;
|
||||
// string s = "";
|
||||
// int nread = -1;
|
||||
// do {
|
||||
// char buf[1024] = {'\0'};
|
||||
// nread = read(fd, buf, sizeof(buf));
|
||||
// if (nread > 0)
|
||||
// s += buf;
|
||||
// } while (nread > 0);
|
||||
// close(fd);
|
||||
// return s;
|
||||
|
||||
string data;
|
||||
ifstream ifs(sFullFileName.c_str());
|
||||
if(ifs.is_open())
|
||||
{
|
||||
data.assign(istreambuf_iterator<char>(ifs), istreambuf_iterator<char>());
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void TC_File::load2str(const string &sFullFileName, vector<char> &buffer)
|
||||
|
Loading…
Reference in New Issue
Block a user