about summary refs log tree commit diff stats
path: root/src/extern
diff options
context:
space:
mode:
Diffstat (limited to 'src/extern')
-rw-r--r--src/extern/stdio.nim8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/extern/stdio.nim b/src/extern/stdio.nim
index 7fc1461d..729b50f6 100644
--- a/src/extern/stdio.nim
+++ b/src/extern/stdio.nim
@@ -15,3 +15,11 @@ proc closeStdout*() =
 
 proc closeStderr*() =
   closeHandle(2, O_WRONLY)
+
+proc safeClose*(fd: cint) =
+  if fd == 0:
+    closeStdin()
+  elif fd == 1 or fd == 2:
+    closeHandle(fd, O_WRONLY)
+  else:
+    discard close(fd)