mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 18:32:11 +00:00
Merge pull request #4314 from abudden/2146-unbuffered-io
Added setStdIoUnbuffered for unbuffered stdio (fixes #2146).
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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.}
|
||||
|
||||
@@ -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
|
||||
------------------
|
||||
|
||||
Reference in New Issue
Block a user