Skip to content

Commit

Permalink
Added setStdIoUnbuffered for unbuffered stdio (fixes #2146).
Browse files Browse the repository at this point in the history
  • Loading branch information
abudden committed Jun 12, 2016
1 parent aadc154 commit 52b4e8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/system.nim
Expand Up @@ -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.

Expand Down
5 changes: 5 additions & 0 deletions lib/system/sysio.nim
Expand Up @@ -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.}
1 change: 1 addition & 0 deletions web/news/version_0_15_released.rst
Expand Up @@ -14,6 +14,7 @@ Changes affecting backwards compatibility
Library Additions
-----------------

- Added ``setStdIoUnbuffered`` proc to ``system.nim`` to enable unbuffered I/O.

Compiler Additions
------------------
Expand Down

0 comments on commit 52b4e8f

Please sign in to comment.