* Replace ftell and fseek with (windows) _ftelli64, _fseeki64 and (posix) ftello, fseeko

* disable large file test
This commit is contained in:
pqflx3 2018-01-31 10:38:37 -05:00 • committed by Andreas Rumpf
commit 8d8df5807b
2 changed files with 38 additions and 9 deletions

View file

@ -47,10 +47,16 @@ when not declared(c_fwrite):
# C routine that is used here:
proc c_fread(buf: pointer, size, n: csize, f: File): csize {.
importc: "fread", header: "<stdio.h>", tags: [ReadIOEffect].}
proc c_fseek(f: File, offset: clong, whence: cint): cint {.
importc: "fseek", header: "<stdio.h>", tags: [].}
proc c_ftell(f: File): clong {.
importc: "ftell", header: "<stdio.h>", tags: [].}
when defined(windows):
proc c_fseek(f: File, offset: int64, whence: cint): cint {.
importc: "_fseeki64", header: "<stdio.h>", tags: [].}
proc c_ftell(f: File): int64 {.
importc: "_ftelli64", header: "<stdio.h>", tags: [].}
else:
proc c_fseek(f: File, offset: int64, whence: cint): cint {.
importc: "fseeko", header: "<stdio.h>", tags: [].}
proc c_ftell(f: File): int64 {.
importc: "ftello", header: "<stdio.h>", tags: [].}
proc c_ferror(f: File): cint {.
importc: "ferror", header: "<stdio.h>", tags: [].}
proc c_setvbuf(f: File, buf: pointer, mode: cint, size: csize): cint {.
@ -210,12 +216,12 @@ proc readAllBuffer(file: File): string =
result.add(buffer)
break
proc rawFileSize(file: File): int =
proc rawFileSize(file: File): int64 =
# this does not raise an error opposed to `getFileSize`
var oldPos = c_ftell(file)
discard c_fseek(file, 0, 2) # seek the end of the file
result = c_ftell(file)
discard c_fseek(file, clong(oldPos), 0)
discard c_fseek(file, oldPos, 0)
proc endOfFile(f: File): bool =
var c = c_fgetc(f)
@ -223,7 +229,7 @@ proc endOfFile(f: File): bool =
return c < 0'i32
#result = c_feof(f) != 0
proc readAllFile(file: File, len: int): string =
proc readAllFile(file: File, len: int64): string =
# We acquire the filesize beforehand and hope it doesn't change.
# Speeds things up.
result = newString(len)
@ -363,7 +369,7 @@ proc open(f: var File, filehandle: FileHandle, mode: FileMode): bool =
result = f != nil
proc setFilePos(f: File, pos: int64, relativeTo: FileSeekPos = fspSet) =
if c_fseek(f, clong(pos), cint(relativeTo)) != 0:
if c_fseek(f, pos, cint(relativeTo)) != 0:
raiseEIO("cannot set file position")
proc getFilePos(f: File): int64 =