mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user