Merge pull request #2512 from spnethw/tmppanel_fix_menu_from_file_list_crash
[far2l.git] / utils / src / ReadWholeFile.cpp
blob3ad8d58508c8a3bc3c01bf4bb78283e0b3752a76
1 #include <fcntl.h>
2 #include "utils.h"
3 #include "ScopeHelpers.h"
5 bool ReadWholeFile(const char *path, std::string &result, size_t limit)
7 FDScope fd(path, O_RDONLY);
8 if (!fd.Valid())
9 return false;
11 for (;;) {
12 char buf[0x1000] = {};
13 ssize_t r = ReadAll(fd, buf, sizeof(buf));
14 if (r > 0) {
15 result.append(buf, r);
16 if (result.size() >= limit) {
17 return true;
20 } else if (r < 0 && result.empty()) {
21 return false;
23 } else {
24 return true;