summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorJacek Sieka <arnetheduck@gmail.com>2016-06-08 23:28:16 +0800
committerJacek Sieka <arnetheduck@gmail.com>2016-06-08 23:28:16 +0800
commit43996c24a0e82dd935f0509bf7c9415ccb573b93 (patch)
treee3443a6fdcfd65af22f069bd1e07869b1552b19b /lib/pure
parentea53cc7fcd470bb88eb9960f8ef79310ac15da50 (diff)
downloadNim-43996c24a0e82dd935f0509bf7c9415ccb573b93.tar.gz
fix errno in os.nim
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/os.nim7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 86dd903e7..8a39096d9 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -51,6 +51,8 @@ proc c_getenv(env: cstring): cstring {.
 proc c_putenv(env: cstring): cint {.
   importc: "putenv", header: "<stdlib.h>".}
 
+var errno {.importc, header: "<errno.h>".}: cint
+
 proc osErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
   ## Retrieves the operating system's error flag, ``errno``.
   ## On Windows ``GetLastError`` is checked before ``errno``.
@@ -74,8 +76,9 @@ proc osErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
                           nil, err, 0, addr(msgbuf), 0, nil) != 0'i32:
           result = $msgbuf
           if msgbuf != nil: localFree(msgbuf)
-  if errno != 0'i32:
-    result = $os.c_strerror(errno)
+  else:
+    if errno != 0'i32:
+      result = $os.c_strerror(errno)
 
 {.push warning[deprecated]: off.}
 proc raiseOSError*(msg: string = "") {.noinline, rtl, extern: "nos$1",