Skip to content

Commit

Permalink
os: faster getFileSize (nim-lang#19438)
Browse files Browse the repository at this point in the history
Use "stat" rather than "open", "seek", and "close" system calls.
The Windows implementation remains the same.
  • Loading branch information
ehmry authored and PMunch committed Mar 28, 2022
1 parent 5ab0757 commit 5f96881
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5f96881

Please sign in to comment.