summary refs log tree commit diff stats
path: root/lib/pure/os.nim
diff options
context:
space:
mode:
authorehmry <ehmry@posteo.net>2022-01-24 20:57:37 +0100
committerGitHub <noreply@github.com>2022-01-24 20:57:37 +0100
commitf7c4fb0014f320824d8f05e2e4d9776c09f51711 (patch)
treec4c29c4f15337c3c1284c410473b737a48f6ab93 /lib/pure/os.nim
parent15f54de5c4ee2f70e1304201ebc8c8634b731c9a (diff)
downloadNim-f7c4fb0014f320824d8f05e2e4d9776c09f51711.tar.gz
os: faster getFileSize (#19438)
Use "stat" rather than "open", "seek", and "close" system calls.
The Windows implementation remains the same.
Diffstat (limited to 'lib/pure/os.nim')
-rw-r--r--lib/pure/os.nim9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 81b432d7f..07040d611 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -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