summary refs log tree commit diff stats
path: root/lib/system/sysio.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-laptop>2010-05-28 23:32:46 +0200
committerAndreas Rumpf <andreas@andreas-laptop>2010-05-28 23:32:46 +0200
commit6c2050912166a4960b40c3825afb1a31cfdde0eb (patch)
treed753cb2baa1d18d4798d64a564fdb692c54146f7 /lib/system/sysio.nim
parente90665bff2e062598b51ada915c4861db6e94a8d (diff)
downloadNim-6c2050912166a4960b40c3825afb1a31cfdde0eb.tar.gz
explicit types for generic routines
Diffstat (limited to 'lib/system/sysio.nim')
-rwxr-xr-xlib/system/sysio.nim11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim
index 3c99a5eed..1dcc2ab3a 100755
--- a/lib/system/sysio.nim
+++ b/lib/system/sysio.nim
@@ -27,6 +27,9 @@ proc strlen(c: cstring): int {.importc: "strlen", nodecl.}
 proc setvbuf(stream: TFile, buf: pointer, typ, size: cint): cint {.
   importc, nodecl.}
 
+proc freopen(path, mode: cstring, stream: TFile): TFile {.importc: "freopen",
+  nodecl.}
+
 proc write(f: TFile, c: cstring) = fputs(c, f)
 
 var
@@ -112,9 +115,7 @@ const
 proc Open(f: var TFile, filename: string,
           mode: TFileMode = fmRead,
           bufSize: int = -1): Bool =
-  var
-    p: pointer
-  p = fopen(filename, FormatOpen[mode])
+  var p: pointer = fopen(filename, FormatOpen[mode])
   result = (p != nil)
   f = cast[TFile](p)
   if bufSize > 0:
@@ -123,6 +124,10 @@ proc Open(f: var TFile, filename: string,
   elif bufSize == 0:
     discard setvbuf(f, nil, IONBF, 0)
 
+proc reopen(f: TFile, filename: string, mode: TFileMode = fmRead): bool = 
+  var p: pointer = freopen(filename, FormatOpen[mode], f)
+  result = p != nil
+
 proc fdopen(filehandle: TFileHandle, mode: cstring): TFile {.
   importc: pccHack & "fdopen", header: "<stdio.h>".}