diff --git a/src/core/p-file.c b/src/core/p-file.c index d98954970f..6e9e917ff3 100644 --- a/src/core/p-file.c +++ b/src/core/p-file.c @@ -405,7 +405,11 @@ REBINT Mode_Syms[] = { len += cnt; SET_FLAG(file->modes, RFM_RESEEK); } - if (cnt > len) return (REBCNT)len; + // Originaly, when the requested part was larger then the reported file's size, + // then the reported file size was used instead. But on Posix there are virtual files, + // where the size is reported as 0. In this case we keep the user's requested length. + // See: https://github.com/Oldes/Rebol-issues/issues/2303 + if (cnt > len && len > 0) return (REBCNT)len; return (REBCNT)cnt; } diff --git a/src/tests/units/port-test.r3 b/src/tests/units/port-test.r3 index ebcb0a2851..59ae60884b 100644 --- a/src/tests/units/port-test.r3 +++ b/src/tests/units/port-test.r3 @@ -524,6 +524,27 @@ if system/platform = 'Windows [ --assert all [error? e: try [append/only p "aa"] e/id = 'bad-refines] try [delete %issue-1894] +if exists? %/proc/cpuinfo [ + --test-- "Reading from /proc files on Linux" + ;@@ https://github.com/Oldes/Rebol-issues/issues/2303 + --assert all [ + not error? info: try [read/string %/proc/cpuinfo] + empty? info ;; empty, because to read this type of file, the size must be specified! + ] + --assert all [ + not error? info: try [read/string/part %/proc/cpuinfo 10000] + print info + 0 < length? info + ] +] + --test-- "Reading an empty file" + --assert all [ + file? write %empty "" + 0 = length? read %empty + 0 = length? read/part %empty 1000 + port? delete %empty + ] + ===end-group=== if system/platform = 'Windows [