Added setStdIoUnbuffered for unbuffered stdio (fixes #2146).

This commit is contained in:
A. S. Budden
2016-06-12 07:40:28 +01:00
parent aadc154c95
commit 52b4e8f661
3 changed files with 9 additions and 0 deletions

View File

@@ -2708,6 +2708,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) {.importc: "fclose", header: "<stdio.h>", tags: [].}
## Closes the file.

View File

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

View File

@@ -14,6 +14,7 @@ Changes affecting backwards compatibility
Library Additions
-----------------
- Added ``setStdIoUnbuffered`` proc to ``system.nim`` to enable unbuffered I/O.
Compiler Additions
------------------