fixed 'system.open' bug

This commit is contained in:
Araq 2014-09-14 11:27:14 +02:00
commit 05f09fafcf

View file

@ -215,11 +215,11 @@ proc open(f: var File, filename: string,
mode: FileMode = fmRead, mode: FileMode = fmRead,
bufSize: int = -1): bool = bufSize: int = -1): bool =
var p: pointer = fopen(filename, FormatOpen[mode]) var p: pointer = fopen(filename, FormatOpen[mode])
result = (p != nil) if p != nil:
result = true
f = cast[File](p) f = cast[File](p)
if bufSize > 0 and bufSize <= high(cint).int: if bufSize > 0 and bufSize <= high(cint).int:
if setvbuf(f, nil, IOFBF, bufSize.cint) != 0'i32: discard setvbuf(f, nil, IOFBF, bufSize.cint)
sysFatal(OutOfMemError, "out of memory")
elif bufSize == 0: elif bufSize == 0:
discard setvbuf(f, nil, IONBF, 0) discard setvbuf(f, nil, IONBF, 0)