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:
parent
15f54de5c4
commit
f7c4fb0014
1 changed files with 4 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue