Core: LoadFile fixed

This commit is contained in:
Mirek Fidler 2022-05-18 10:21:49 +02:00
parent 3fdd8be072
commit 9b1472ba70
2 changed files with 7 additions and 1 deletions

View file

@ -8,4 +8,10 @@ CONSOLE_APP_MAIN
Cout() << s; Cout() << s;
ASSERT(s.GetCount() > 0); ASSERT(s.GetCount() > 0);
ASSERT(LoadFile("/proc/this_file_does_not_exist").IsVoid()); ASSERT(LoadFile("/proc/this_file_does_not_exist").IsVoid());
String path = GetHomeDirFile("empty_file");
SaveFile(path, String());
s = LoadFile(path);
DDUMP(s.GetCount());
ASSERT(!s.IsVoid() && s.GetCount() == 0);
DeleteFile(path);
} }

View file

@ -1227,7 +1227,7 @@ String LoadFile(const char *filename) {
s.SetCount(n + CHUNK); s.SetCount(n + CHUNK);
int len = read(fd, ~s + n, CHUNK); int len = read(fd, ~s + n, CHUNK);
if(len != CHUNK) { if(len != CHUNK) {
if(len > 0) if(len >= 0)
s.SetCount(n + len); s.SetCount(n + len);
return s; return s;
} }