bugfix: don't change OSError()'s behaviour

This commit is contained in:
Araq 2011-05-08 09:23:50 +02:00
commit 1893f4101a
2 changed files with 11 additions and 14 deletions

View file

@ -1,7 +1,7 @@
# #
# #
# Nimrod's Runtime Library # Nimrod's Runtime Library
# (c) Copyright 2010 Andreas Rumpf # (c) Copyright 2011 Andreas Rumpf
# #
# See the file "copying.txt", included in this # See the file "copying.txt", included in this
# distribution, for details about the copyright. # distribution, for details about the copyright.
@ -148,8 +148,9 @@ const
## for example, the '.' in ``os.nim``. ## for example, the '.' in ``os.nim``.
proc OSErrorMsg*(): string {.rtl, extern: "nos$1".} = proc OSErrorMsg*(): string {.rtl, extern: "nos$1".} =
## Retrieves the operating system's error flag, ``errno`` on Posix and ## Retrieves the operating system's error flag, ``errno``.
## ``GetLastError`` on Windows. ## On Windows ``GetLastError`` is checked before ``errno``.
## Returns "" if no error occured.
result = "" result = ""
when defined(Windows): when defined(Windows):
var err = GetLastError() var err = GetLastError()
@ -161,9 +162,8 @@ proc OSErrorMsg*(): string {.rtl, extern: "nos$1".} =
if msgbuf != nil: if msgbuf != nil:
LocalFree(msgbuf) LocalFree(msgbuf)
result = m result = m
else: if errno != 0'i32:
if errno != 0'i32: result = $os.strerror(errno)
result = $os.strerror(errno)
proc OSError*(msg: string = "") {.noinline, rtl, extern: "nos$1".} = proc OSError*(msg: string = "") {.noinline, rtl, extern: "nos$1".} =
## raises an EOS exception with the given message ``msg``. ## raises an EOS exception with the given message ``msg``.
@ -173,10 +173,7 @@ proc OSError*(msg: string = "") {.noinline, rtl, extern: "nos$1".} =
## If no error flag is set, the message ``unknown OS error`` is used. ## If no error flag is set, the message ``unknown OS error`` is used.
if len(msg) == 0: if len(msg) == 0:
var m = OSErrorMsg() var m = OSErrorMsg()
if m != "": raise newException(EOS, if m.len > 0: m else: "unknown OS error")
raise newException(EOS, m)
else:
raise newException(EOS, "unknown OS error")
else: else:
raise newException(EOS, msg) raise newException(EOS, msg)

View file

@ -200,10 +200,10 @@ proc execProcesses*(cmds: openArray[string],
result = max(waitForExit(p), result) result = max(waitForExit(p), result)
proc select*(readfds: var seq[PProcess], timeout = 500): int proc select*(readfds: var seq[PProcess], timeout = 500): int
## select with a sensible Nimrod interface. `timeout` is in miliseconds. ## `select` with a sensible Nimrod interface. `timeout` is in miliseconds.
## Specify -1 for no timeout. Returns the number of file handles that are ## Specify -1 for no timeout. Returns the number of processes that are
## ready. The processes that are ready to be read from are removed from ## ready to read from. The processes that are ready to be read from are
## `readfds`. ## removed from `readfds`.
when not defined(useNimRtl): when not defined(useNimRtl):
proc execProcess(command: string, proc execProcess(command: string,