Merge pull request #4314 from abudden/2146-unbuffered-io

Added setStdIoUnbuffered for unbuffered stdio (fixes #2146).
This commit is contained in:
Andreas Rumpf
2016-06-14 01:57:02 +02:00
committed by GitHub
3 changed files with 12 additions and 0 deletions

View File

@@ -2715,6 +2715,9 @@ when not defined(JS): #and not defined(nimscript):
##
## Default mode is readonly. Returns true iff the file could be reopened.
proc setStdIoUnbuffered*() {.tags: [], benign.}
## Configures `stdin`, `stdout` and `stderr` to be unbuffered.
proc close*(f: File) {.tags: [].}
## Closes the file.

View File

@@ -369,4 +369,12 @@ proc writeFile(filename, content: string) =
else:
sysFatal(IOError, "cannot open: ", filename)
proc setStdIoUnbuffered() =
when declared(stdout):
discard c_setvbuf(stdout, nil, IONBF, 0)
when declared(stderr):
discard c_setvbuf(stderr, nil, IONBF, 0)
when declared(stdin):
discard c_setvbuf(stdin, nil, IONBF, 0)
{.pop.}

View File

@@ -16,6 +16,7 @@ Library Additions
- Added ``readHeaderRow`` and ``rowEntry`` to ``parsecsv.nim`` to provide
a lightweight alternative to python's ``csv.DictReader``.
- Added ``setStdIoUnbuffered`` proc to ``system.nim`` to enable unbuffered I/O.
Compiler Additions
------------------