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
commit f7c4fb0014
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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