mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: LoadFile fixed to work with /proc pseudofiles
This commit is contained in:
parent
a5563f9322
commit
34cdcee068
4 changed files with 41 additions and 1 deletions
11
autotest/LoadProcFile/LoadProcFile.cpp
Normal file
11
autotest/LoadProcFile/LoadProcFile.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
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());
|
||||
}
|
||||
9
autotest/LoadProcFile/LoadProcFile.upp
Normal file
9
autotest/LoadProcFile/LoadProcFile.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
LoadProcFile.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -451,7 +451,7 @@ void IconDes::SaveUndo()
|
|||
return;
|
||||
Slot& c = Current();
|
||||
Vector<ImageIml> 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue