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)
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue