--os:standalone works again

This commit is contained in:
Araq 2013-06-30 21:15:28 +02:00
commit 52851b722d
16 changed files with 552 additions and 621 deletions

View file

@ -16,39 +16,44 @@
# of the standard library!
proc fputs(c: cstring, f: TFile) {.importc: "fputs", noDecl, tags: [FWriteIO].}
proc fgets(c: cstring, n: int, f: TFile): cstring {.importc: "fgets", noDecl,
tags: [FReadIO].}
proc fgetc(stream: TFile): cint {.importc: "fgetc", nodecl, tags: [FReadIO].}
proc ungetc(c: cint, f: TFile) {.importc: "ungetc", nodecl, tags: [].}
proc putc(c: Char, stream: TFile) {.importc: "putc", nodecl, tags: [FWriteIO].}
proc fprintf(f: TFile, frmt: CString) {.importc: "fprintf", nodecl, varargs,
tags: [FWriteIO].}
proc strlen(c: cstring): int {.importc: "strlen", nodecl, tags: [].}
proc fputs(c: cstring, f: TFile) {.importc: "fputs", header: "<stdio.h>",
tags: [FWriteIO].}
proc fgets(c: cstring, n: int, f: TFile): cstring {.
importc: "fgets", header: "<stdio.h>", tags: [FReadIO].}
proc fgetc(stream: TFile): cint {.importc: "fgetc", header: "<stdio.h>",
tags: [FReadIO].}
proc ungetc(c: cint, f: TFile) {.importc: "ungetc", header: "<stdio.h>",
tags: [].}
proc putc(c: Char, stream: TFile) {.importc: "putc", header: "<stdio.h>",
tags: [FWriteIO].}
proc fprintf(f: TFile, frmt: CString) {.importc: "fprintf",
header: "<stdio.h>", varargs, tags: [FWriteIO].}
proc strlen(c: cstring): int {.
importc: "strlen", header: "<string.h>", tags: [].}
# C routine that is used here:
proc fread(buf: Pointer, size, n: int, f: TFile): int {.
importc: "fread", noDecl, tags: [FReadIO].}
importc: "fread", header: "<stdio.h>", tags: [FReadIO].}
proc fseek(f: TFile, offset: clong, whence: int): int {.
importc: "fseek", noDecl, tags: [].}
proc ftell(f: TFile): int {.importc: "ftell", noDecl, tags: [].}
importc: "fseek", header: "<stdio.h>", tags: [].}
proc ftell(f: TFile): int {.importc: "ftell", header: "<stdio.h>", tags: [].}
proc setvbuf(stream: TFile, buf: pointer, typ, size: cint): cint {.
importc, nodecl, tags: [].}
importc, header: "<stdio.h>", tags: [].}
{.push stackTrace:off, profiler:off.}
proc write(f: TFile, c: cstring) = fputs(c, f)
{.pop.}
var
IOFBF {.importc: "_IOFBF", nodecl.}: cint
IONBF {.importc: "_IONBF", nodecl.}: cint
IOFBF {.importc: "_IOFBF", header: "<stdio.h>".}: cint
IONBF {.importc: "_IONBF", header: "<stdio.h>".}: cint
const
buf_size = 4000
proc raiseEIO(msg: string) {.noinline, noreturn.} =
raise newException(EIO, msg)
sysFatal(EIO, msg)
proc readLine(f: TFile, line: var TaintedString): bool =
# of course this could be optimized a bit; but IO is slow anyway...
@ -197,7 +202,7 @@ proc Open(f: var TFile, filename: string,
f = cast[TFile](p)
if bufSize > 0 and bufSize <= high(cint).int:
if setvbuf(f, nil, IOFBF, bufSize.cint) != 0'i32:
raise newException(EOutOfMemory, "out of memory")
sysFatal(EOutOfMemory, "out of memory")
elif bufSize == 0:
discard setvbuf(f, nil, IONBF, 0)