diff options
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/osproc.nim | 14 | ||||
-rw-r--r-- | lib/pure/strscans.nim | 6 | ||||
-rw-r--r-- | lib/pure/times.nim | 29 |
3 files changed, 31 insertions, 18 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 76bd2dfe1..1d43bb321 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -965,10 +965,16 @@ elif not defined(useNimRtl): var ret : int var status : cint = 1 ret = waitpid(p.id, status, WNOHANG) - if WIFEXITED(status): - p.exitStatus = status - if ret == 0: return true # Can't establish status. Assume running. - result = ret == int(p.id) + if ret == int(p.id): + if WIFEXITED(status): + p.exitStatus = status + return false + else: + return true + elif ret == 0: + return true # Can't establish status. Assume running. + else: + return false proc terminate(p: Process) = if kill(p.id, SIGTERM) != 0'i32: diff --git a/lib/pure/strscans.nim b/lib/pure/strscans.nim index 246f018c5..fc400173f 100644 --- a/lib/pure/strscans.nim +++ b/lib/pure/strscans.nim @@ -76,7 +76,7 @@ to a variable (that was passed to the ``scanf`` macro) while ``$[]`` merely optional tokens. -In this example, we define a helper proc ``skipSep`` that skips some separators +In this example, we define a helper proc ``someSep`` that skips some separators which we then use in our scanf pattern to help us in the matching process: .. code-block:: nim @@ -86,14 +86,14 @@ which we then use in our scanf pattern to help us in the matching process: result = 0 while input[start+result] in seps: inc result - if scanf(input, "$w${someSep}$w", key, value): + if scanf(input, "$w$[someSep]$w", key, value): ... It also possible to pass arguments to a user definable matcher: .. code-block:: nim - proc ndigits(input: string; start: int; intVal: var int; n: int): int = + proc ndigits(input: string; intVal: var int; start: int; n: int): int = # matches exactly ``n`` digits. Matchers need to return 0 if nothing # matched or otherwise the number of processed chars. var x = 0 diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 1767a37be..cf4e7dde6 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -436,6 +436,11 @@ when not defined(JS): TimeInfoPtr = ptr StructTM Clock {.importc: "clock_t".} = distinct int + when not defined(windows): + # This is not ANSI C, but common enough + proc timegm(t: StructTM): Time {. + importc: "timegm", header: "<time.h>", tags: [].} + proc localtime(timer: ptr Time): TimeInfoPtr {. importc: "localtime", header: "<time.h>", tags: [].} proc gmtime(timer: ptr Time): TimeInfoPtr {. @@ -515,20 +520,22 @@ when not defined(JS): # the conversion is not expensive proc timeInfoToTime(timeInfo: TimeInfo): Time = - var cTimeInfo = timeInfo # for C++ we have to make a copy, - # because the header of mktime is broken in my version of libc - result = mktime(timeInfoToTM(cTimeInfo)) - # mktime is defined to interpret the input as local time. As timeInfoToTM - # does ignore the timezone, we need to adjust this here. - result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone) + toTime(timeInfo) proc toTime(timeInfo: TimeInfo): Time = - var cTimeInfo = timeInfo # for C++ we have to make a copy, + var cTimeInfo = timeInfo # for C++ we have to make a copy # because the header of mktime is broken in my version of libc - result = mktime(timeInfoToTM(cTimeInfo)) - # mktime is defined to interpret the input as local time. As timeInfoToTM - # does ignore the timezone, we need to adjust this here. - result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone) + + when defined(windows): + # On Windows `mktime` is broken enough to make this work. + result = mktime(timeInfoToTM(cTimeInfo)) + # mktime is defined to interpret the input as local time. As timeInfoToTM + # does ignore the timezone, we need to adjust this here. + result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone) + else: + result = timegm(timeInfoToTM(cTimeInfo)) + # As timeInfoToTM does ignore the timezone, we need to adjust this here. + result = Time(TimeImpl(result) + timeInfo.timezone) const epochDiff = 116444736000000000'i64 |