Skip to content

Commit 7806ec5

Browse files
authored
Making TCC work again on Windows --cpu:amd64 - fix #16326 (#19221)
* fix #16326 * removing comments
1 parent cd592ed commit 7806ec5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Diff for: lib/system/io.nim

+16-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,22 @@ when defined(windows):
109109
else:
110110
proc c_fseek(f: File, offset: int64, whence: cint): cint {.
111111
importc: "_fseeki64", header: "<stdio.h>", tags: [].}
112-
proc c_ftell(f: File): int64 {.
113-
importc: "_ftelli64", header: "<stdio.h>", tags: [].}
112+
when defined(tcc):
113+
proc c_fsetpos(f: File, pos: var int64): int32 {.
114+
importc: "fsetpos", header: "<stdio.h>", tags: [].}
115+
proc c_fgetpos(f: File, pos: var int64): int32 {.
116+
importc: "fgetpos", header: "<stdio.h>", tags: [].}
117+
proc c_telli64(f: cint): int64 {.
118+
importc: "_telli64", header: "<io.h>", tags: [].}
119+
proc c_ftell(f: File): int64 =
120+
# Taken from https://pt.osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.4-trunk/mingwrt/mingwex/stdio/ftelli64.c
121+
result = -1'i64
122+
var pos: int64
123+
if c_fgetpos(f, pos) == 0 and c_fsetpos(f, pos) == 0:
124+
result = c_telli64(c_fileno(f))
125+
else:
126+
proc c_ftell(f: File): int64 {.
127+
importc: "_ftelli64", header: "<stdio.h>", tags: [].}
114128
else:
115129
proc c_fseek(f: File, offset: int64, whence: cint): cint {.
116130
importc: "fseeko", header: "<stdio.h>", tags: [].}

0 commit comments

Comments
 (0)