Skip to content

Commit

Permalink
FIX: issue #2430 (write/lines only writes end-of-lines if argument is…
Browse files Browse the repository at this point in the history
… block)
  • Loading branch information
qtxie committed Feb 12, 2017
1 parent 67f6694 commit 0ca9c1d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions runtime/simple-io.reds
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ simple-io: context [
append? [logic!]
lines? [logic!]
unicode? [logic!]
block? [logic!]
return: [integer!]
/local
file [integer!]
Expand Down Expand Up @@ -808,11 +809,12 @@ simple-io: context [
while [value < tail][
data: value-to-buffer value -1 :size binary? buffer
write-data file data size
write-data file as byte-ptr! lineend lf-sz
ret: write-data file as byte-ptr! lineend lf-sz
value: value + 1
]
][
ret: write-data file data size
write-data file data size
if block? [ret: write-data file as byte-ptr! lineend lf-sz]
]
if filename <> null [close-file file]
ret
Expand Down Expand Up @@ -1060,7 +1062,9 @@ simple-io: context [
offset [integer!]
buffer [red-string!]
name [c-string!]
block? [logic!]
][
block?: no
offset: -1
limit: -1
if OPTION?(part) [
Expand All @@ -1079,15 +1083,16 @@ simple-io: context [

either all [lines? TYPE_OF(data) = TYPE_BLOCK][
buf: as byte-ptr! data
block?: yes
][
lines?: no
if lines? [block?: yes lines?: no]
len: 0
buffer: string/rs-make-at stack/push* 16
buf: value-to-buffer data limit :len binary? buffer
]

name: either null? filename [null][file/to-OS-path filename]
type: write-file name buf len offset binary? append? lines? yes
type: write-file name buf len offset binary? append? lines? yes block?
if negative? type [fire [TO_ERROR(access cannot-open) filename]]
type
]
Expand Down

0 comments on commit 0ca9c1d

Please sign in to comment.