Skip to content

Commit

Permalink
fix nim-lang#9634: debugging a program using execCmdEx now works
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Apr 7, 2019
1 parent 28a83a8 commit 4563526
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/system/io.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ proc strerror(errnum: cint): cstring {.importc, header: "<string.h>".}
when not defined(NimScript):
var
errno {.importc, header: "<errno.h>".}: cint ## error variable
EINTR {.importc: "EINTR", header: "<errno.h>".}: cint
proc c_printf(frmt: cstring): cint {.
importc: "printf", header: "<stdio.h>", varargs, discardable.}


proc checkErr(f: File) =
when not defined(NimScript):
Expand All @@ -137,14 +141,24 @@ proc checkErr(f: File) =
# shouldn't happen
quit(1)



{.push stackTrace:off, profiler:off.}
proc readBuffer*(f: File, buffer: pointer, len: Natural): int {.
tags: [ReadIOEffect], benign.} =
## reads `len` bytes into the buffer pointed to by `buffer`. Returns
## the actual number of bytes that have been read which may be less than
## `len` (if not as many bytes are remaining), but not greater.
result = c_fread(buffer, 1, len, f)
if result != len: checkErr(f)
while true:
result = c_fread(buffer, 1, len, f)
if result == len: return result
when not defined(NimScript):
if errno == EINTR:
errno = 0
c_clearerr(f)
continue
checkErr(f)
break

proc readBytes*(f: File, a: var openArray[int8|uint8], start, len: Natural): int {.
tags: [ReadIOEffect], benign.} =
Expand Down

0 comments on commit 4563526

Please sign in to comment.