From 76a6757ee9e838326519ffb30a81dc60667d253d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 25 Feb 2019 18:03:44 +0000 Subject: [PATCH] Add `os.file_size_from_path` --- core/os/os.odin | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/os/os.odin b/core/os/os.odin index eda3b66cf..9db84ddfe 100644 --- a/core/os/os.odin +++ b/core/os/os.odin @@ -51,6 +51,20 @@ write_encoded_rune :: proc(fd: Handle, r: rune) { } +file_size_from_path :: proc(path: string) -> i64 { + fd, err := open(path, O_RDONLY, 0); + if err != 0 { + return -1; + } + defer close(fd); + + length: i64; + if length, err = file_size(fd); err != 0 { + return -1; + } + return length; +} + read_entire_file :: proc(name: string) -> (data: []byte, success: bool) { fd, err := open(name, O_RDONLY, 0); if err != 0 {