From 6d5bd8beadc0558b0b0d74e536eccedae0cbaf2f Mon Sep 17 00:00:00 2001 From: kennethmaples Date: Tue, 29 Dec 2020 17:45:19 +0800 Subject: [PATCH] Fix layout of Stat for linux and make usage consistent across unix variants --- core/os/os_darwin.odin | 10 +++++----- core/os/os_freebsd.odin | 16 +++++++++------- core/os/os_linux.odin | 14 ++++++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index 36cd13804..818909923 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -186,7 +186,7 @@ RTLD_FIRST :: 0x100; // "Argv" arguments converted to Odin strings args := _alloc_command_line_arguments(); -_File_Time :: struct { +Unix_File_Time :: struct { seconds: i64, nanoseconds: i64, } @@ -200,10 +200,10 @@ Stat :: struct { gid: u32, // Group ID of the file's group rdev: i32, // Device ID, if device - last_access: _File_Time, // Time of last access - modified: _File_Time, // Time of last modification - status_change: _File_Time, // Time of last status change - created: _File_Time, // Time of creation + last_access: Unix_File_Time, // Time of last access + modified: Unix_File_Time, // Time of last modification + status_change: Unix_File_Time, // Time of last status change + created: Unix_File_Time, // Time of creation size: i64, // Size of the file, in bytes blocks: i64, // Number of blocks allocated for the file diff --git a/core/os/os_freebsd.odin b/core/os/os_freebsd.odin index 03c44a1ae..fa439141e 100644 --- a/core/os/os_freebsd.odin +++ b/core/os/os_freebsd.odin @@ -144,7 +144,7 @@ RTLD_NOLOAD :: 0x02000; args := _alloc_command_line_arguments(); -_File_Time :: struct { +Unix_File_Time :: struct { seconds: i64, nanoseconds: c.long, } @@ -162,10 +162,10 @@ Stat :: struct { _padding1: i32, rdev: u64, - last_access: File_Time, - modified: File_Time, - status_change: File_Time, - birthtime: File_Time, + last_access: Unix_File_Time, + modified: Unix_File_Time, + status_change: Unix_File_Time, + birthtime: Unix_File_Time, size: i64, blocks: i64, @@ -328,7 +328,8 @@ last_write_time :: proc(fd: Handle) -> (File_Time, Errno) { if err != ERROR_NONE { return 0, err; } - return File_Time(s.modified), ERROR_NONE; + modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds; + return File_Time(modified), ERROR_NONE; } last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) { @@ -336,7 +337,8 @@ last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) { if err != ERROR_NONE { return 0, err; } - return File_Time(s.modified), ERROR_NONE; + modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds; + return File_Time(modified), ERROR_NONE; } stat :: inline proc(path: string) -> (Stat, Errno) { diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index 275a1cf81..cfa5f9c44 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -179,7 +179,7 @@ RTLD_GLOBAL :: 0x100; // "Argv" arguments converted to Odin strings args := _alloc_command_line_arguments(); -_File_Time :: struct { +Unix_File_Time :: struct { seconds: i64, nanoseconds: i64, } @@ -197,9 +197,9 @@ Stat :: struct { block_size: i64, // Optimal bllocksize for I/O blocks: i64, // Number of 512-byte blocks allocated - last_access: File_Time, // Time of last access - status_change: File_Time, // Time of last status change - modified: File_Time, // Time of last modification + last_access: Unix_File_Time, // Time of last access + modified: Unix_File_Time, // Time of last modification + status_change: Unix_File_Time, // Time of last status change _reserve1, _reserve2, @@ -364,7 +364,8 @@ last_write_time :: proc(fd: Handle) -> (File_Time, Errno) { if err != ERROR_NONE { return 0, err; } - return File_Time(s.modified), ERROR_NONE; + modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds; + return File_Time(modified), ERROR_NONE; } last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) { @@ -372,7 +373,8 @@ last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) { if err != ERROR_NONE { return 0, err; } - return File_Time(s.modified), ERROR_NONE; + modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds; + return File_Time(modified), ERROR_NONE; } stat :: inline proc(path: string) -> (Stat, Errno) {