Skip to content

Commit ced5916

Browse files
committed
FIX: open does not reset the internal file pointer of a previously closed file port
fixes: Oldes/Rebol-issues#1456
1 parent ff05fe5 commit ced5916

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/core/p-file.c

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
if (GET_FLAG(file->modes, RFM_NAME_MEM)) {
7777
//NOTE: file->file.path will get GC'd
7878
file->file.path = 0;
79+
file->file.index = 0;
7980
CLR_FLAG(file->modes, RFM_NAME_MEM);
8081
}
8182
SET_CLOSED(file);

src/tests/units/port-test.r3

+16
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ if system/platform = 'Windows [
152152
--assert "<foo>" = read/string write %foo <foo>
153153
delete %foo
154154

155+
--test- "open/close file"
156+
;@@ https://github.com/Oldes/Rebol-issues/issues/1456
157+
file: %tmp-1456
158+
write file "abc"
159+
--assert #{616263} = read file
160+
port: open file
161+
--assert #{616263} = read port
162+
--assert open? port
163+
--assert empty? read port ; because the port is still open, but we are at tail already
164+
close port
165+
--assert not open? port
166+
--assert #{616263} = read port ;port was not one, so it's opened for read action
167+
--assert not open? port ;but was closed again by read
168+
--assert #{616263} = read port ;so next read is again full
169+
delete %tmp-1456
170+
155171
===end-group===
156172

157173
===start-group=== "HTTP scheme"

0 commit comments

Comments
 (0)