os: faster getFileSize (#19438)

Use "stat" rather than "open", "seek", and "close" system calls.
The Windows implementation remains the same.
This commit is contained in:
ehmry
2022-01-24 20:57:37 +01:00
committed by GitHub
parent 15f54de5c4
commit f7c4fb0014

View File

@@ -3216,11 +3216,10 @@ proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
result = rdFileSize(a)
findClose(resA)
else:
var f: File
if open(f, file):
result = getFileSize(f)
close(f)
else: raiseOSError(osLastError(), file)
var rawInfo: Stat
if stat(file, rawInfo) < 0'i32:
raiseOSError(osLastError(), file)
rawInfo.st_size
when defined(windows) or weirdTarget:
type