Skip to content

Commit de294f3

Browse files
committed
FIX: correctly read POSIX virtual files in chunks using an open port
related to: Oldes/Rebol-issues#2303
1 parent d0f3bfd commit de294f3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/core/p-file.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,16 @@ REBINT Mode_Syms[] = {
391391
**
392392
***********************************************************************/
393393
{
394-
REBI64 len; // maximum size
394+
REBI64 len = 0; // maximum size
395395
REBI64 cnt;
396396
// int what_if_it_changed;
397397

398398
// Compute and bound bytes remaining:
399-
len = file->file.size - file->file.index; // already read
400-
if (len < 0) return 0;
401-
len &= MAX_READ_MASK; // limit the size
399+
if (file->file.size > 0) {
400+
len = file->file.size - file->file.index; // already read
401+
if (len < 0) return 0;
402+
len &= MAX_READ_MASK; // limit the size
403+
}
402404

403405
// Return requested length:
404406
if (!D_REF(arg)) return (REBCNT)len;

src/tests/units/port-test.r3

+9
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,15 @@ if exists? %/proc/cpuinfo [
598598
not error? info: try [read/part %/proc/cpuinfo 10]
599599
10 == length? info
600600
]
601+
;; read a POSIX virtual file in chunks using an open port
602+
--assert all [
603+
port? port: try [open/read %/proc/cpuinfo]
604+
bin: make binary! 16000
605+
while [not empty? tmp: read/part port 1024][append bin tmp]
606+
equal? bin try [read %/proc/cpuinfo]
607+
port? try [close port]
608+
not open? port
609+
]
601610
]
602611
--test-- "Reading an empty file"
603612
--assert all [

0 commit comments

Comments
 (0)