vm: FFI improvements

This commit is contained in:
Araq 2013-12-23 20:12:13 +01:00
commit 32ef1f8f32
6 changed files with 56 additions and 28 deletions

View file

@ -45,9 +45,17 @@ proc setvbuf(stream: TFile, buf: pointer, typ, size: cint): cint {.
proc write(f: TFile, c: cstring) = fputs(c, f)
{.pop.}
var
IOFBF {.importc: "_IOFBF", nodecl.}: cint
IONBF {.importc: "_IONBF", nodecl.}: cint
when NoFakeVars:
when defined(windows):
const
IOFBF = cint(0)
IONBF = cint(4)
else:
{.error: "IOFBF not ported to your platform".}
else:
var
IOFBF {.importc: "_IOFBF", nodecl.}: cint
IONBF {.importc: "_IONBF", nodecl.}: cint
const
buf_size = 4000
@ -149,7 +157,7 @@ proc writeFile(filename, content: string) =
finally:
close(f)
proc EndOfFile(f: TFile): bool =
proc endOfFile(f: TFile): bool =
# do not blame me; blame the ANSI C standard this is so brain-damaged
var c = fgetc(f)
ungetc(c, f)
@ -223,10 +231,10 @@ proc fwrite(buf: Pointer, size, n: int, f: TFile): int {.
proc readBuffer(f: TFile, buffer: pointer, len: int): int =
result = fread(buffer, 1, len, f)
proc ReadBytes(f: TFile, a: var openarray[int8], start, len: int): int =
proc readBytes(f: TFile, a: var openarray[int8], start, len: int): int =
result = readBuffer(f, addr(a[start]), len)
proc ReadChars(f: TFile, a: var openarray[char], start, len: int): int =
proc readChars(f: TFile, a: var openarray[char], start, len: int): int =
result = readBuffer(f, addr(a[start]), len)
{.push stackTrace:off, profiler:off.}