From: Brendan Hansen Date: Thu, 18 Jan 2024 00:24:07 +0000 (-0600) Subject: added: timestamps to file stats X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8aac524677ebd6ce9b625cea428b3091ca0fa26c;p=onyx.git added: timestamps to file stats --- diff --git a/core/os/file.onyx b/core/os/file.onyx index c2c791f8..965046fd 100644 --- a/core/os/file.onyx +++ b/core/os/file.onyx @@ -50,6 +50,9 @@ FileType :: enum { FileStat :: struct { size: i64; type: FileType; + change_time: u64; // in milliseconds + accessed_time: u64; // in milliseconds + modified_time: u64; // in milliseconds } file_exists :: fs.__file_exists diff --git a/core/runtime/platform/wasi/wasi_fs.onyx b/core/runtime/platform/wasi/wasi_fs.onyx index de1c23a3..b963188c 100644 --- a/core/runtime/platform/wasi/wasi_fs.onyx +++ b/core/runtime/platform/wasi/wasi_fs.onyx @@ -119,6 +119,9 @@ __file_stat :: (path: str, out: &os.FileStat) -> bool { if err == .Success { exists = true; out.size = ~~ fs.size; + out.change_time = fs.ctim / 1000000; + out.accessed_time = fs.atim / 1000000; + out.modified_time = fs.mtim / 1000000; switch fs.filetype { case .RegularFile do out.type = .RegularFile; @@ -356,4 +359,4 @@ __dir_remove :: (path: str) -> bool { #if !#defined(runtime.vars.WASIX) { __chdir :: (path: str) => false __getcwd :: () => "" -} \ No newline at end of file +} diff --git a/shared/include/bh.h b/shared/include/bh.h index 5f55a52b..76bf84a4 100644 --- a/shared/include/bh.h +++ b/shared/include/bh.h @@ -428,6 +428,9 @@ typedef struct bh_file_contents { typedef struct bh_file_stats { isize size; u32 file_type; + u64 change_time; + u64 accessed_time; + u64 modified_time; } bh_file_stats; bh_file_error bh_file_get_standard(bh_file* file, bh_file_standard stand); @@ -1905,6 +1908,10 @@ b32 bh_file_contents_free(bh_file_contents* contents) { return 1; } +static u64 timespec_to_ms(struct timespec t) { + return t.tv_sec * 1000 + t.tv_nsec / 1000000; +} + b32 bh_file_stat(char const* filename, bh_file_stats* out) { struct stat s; if (stat(filename, &s) == -1) { @@ -1912,6 +1919,9 @@ b32 bh_file_stat(char const* filename, bh_file_stats* out) { } out->size = s.st_size; + out->modified_time = timespec_to_ms(s.st_mtim); + out->accessed_time = timespec_to_ms(s.st_atim); + out->change_time = timespec_to_ms(s.st_ctim); if ((s.st_mode & S_IFMT) == S_IFDIR) out->file_type = BH_FILE_TYPE_DIRECTORY; if ((s.st_mode & S_IFMT) == S_IFREG) out->file_type = BH_FILE_TYPE_FILE;