diff --git a/autotest/LoadProcFile/LoadProcFile.cpp b/autotest/LoadProcFile/LoadProcFile.cpp new file mode 100644 index 000000000..e196ab165 --- /dev/null +++ b/autotest/LoadProcFile/LoadProcFile.cpp @@ -0,0 +1,11 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + String s = LoadFile("/proc/meminfo"); + Cout() << s; + ASSERT(s.GetCount() > 0); + ASSERT(LoadFile("/proc/this_file_does_not_exist").IsVoid()); +} diff --git a/autotest/LoadProcFile/LoadProcFile.upp b/autotest/LoadProcFile/LoadProcFile.upp new file mode 100644 index 000000000..d4e879bc5 --- /dev/null +++ b/autotest/LoadProcFile/LoadProcFile.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + LoadProcFile.cpp; + +mainconfig + "" = ""; + diff --git a/uppsrc/Core/Stream.cpp b/uppsrc/Core/Stream.cpp index 716fe5f15..7bbb9a28c 100644 --- a/uppsrc/Core/Stream.cpp +++ b/uppsrc/Core/Stream.cpp @@ -1216,6 +1216,26 @@ String LoadStream(Stream& in) { String LoadFile(const char *filename) { FindFile ff(filename); if(ff && ff.IsFile()) { + #ifdef PLATFORM_POSIX + if(ff.GetLength() == 0) { // handle speciale cases like /proc/... + int fd = open(filename,O_RDONLY); + if(fd >= 0) { + const int CHUNK = 16; + StringBuffer s; + for(;;) { + int n = s.GetCount(); + s.SetCount(n + CHUNK); + int len = read(fd, ~s + n, CHUNK); + if(len != CHUNK) { + if(len > 0) + s.SetCount(n + len); + return s; + } + } + } + return String::GetVoid(); + } + #endif FileIn in(filename); return LoadStream(in); } diff --git a/uppsrc/IconDes/IconDes.cpp b/uppsrc/IconDes/IconDes.cpp index 3b040c8ff..4d9c5e16f 100644 --- a/uppsrc/IconDes/IconDes.cpp +++ b/uppsrc/IconDes/IconDes.cpp @@ -451,7 +451,7 @@ void IconDes::SaveUndo() return; Slot& c = Current(); Vector undo = UnpackImlData(c.undo); - int maxn = minmax((single_mode ? 4000000 : 400000) / max((int)c.image.GetLength(), 1), 4, 128); + int maxn = minmax((single_mode ? 4000000 : 400000) / max((int)tc.image.GetLength(), 1), 4, 128); while(undo.GetCount() > maxn) undo.Remove(0); if(undo.GetCount() && undo.Top().image == c.image)