diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index c7e1750d6..616e167a1 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -1026,7 +1026,7 @@ absolute_path_from_handle :: proc(fd: Handle) -> (path: string, err: Error) { } @(require_results) -absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { +absolute_path_from_relative :: proc(rel: string, allocator := context.allocator) -> (path: string, err: Error) { rel := rel if rel == "" { rel = "." @@ -1041,9 +1041,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { } defer _unix_free(rawptr(path_ptr)) - path = strings.clone(string(path_ptr)) - - return path, nil + return strings.clone(string(path_ptr), allocator) } access :: proc(path: string, mask: int) -> bool { diff --git a/core/os/os_freebsd.odin b/core/os/os_freebsd.odin index f617cf973..837e79f4d 100644 --- a/core/os/os_freebsd.odin +++ b/core/os/os_freebsd.odin @@ -789,7 +789,7 @@ absolute_path_from_handle :: proc(fd: Handle) -> (string, Error) { } @(require_results) -absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { +absolute_path_from_relative :: proc(rel: string, allocator := context.allocator) -> (path: string, err: Error) { rel := rel if rel == "" { rel = "." @@ -804,10 +804,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { } defer _unix_free(rawptr(path_ptr)) - - path = strings.clone(string(path_ptr)) - - return path, nil + return strings.clone(string(path_ptr), allocator) } access :: proc(path: string, mask: int) -> (bool, Error) { diff --git a/core/os/os_haiku.odin b/core/os/os_haiku.odin index 0d2c334be..4ad370724 100644 --- a/core/os/os_haiku.odin +++ b/core/os/os_haiku.odin @@ -431,7 +431,7 @@ absolute_path_from_handle :: proc(fd: Handle) -> (string, Error) { } @(require_results) -absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { +absolute_path_from_relative :: proc(rel: string, allocator := context.allocator) -> (path: string, err: Error) { rel := rel if rel == "" { rel = "." @@ -447,9 +447,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { defer _unix_free(path_ptr) path_cstr := cstring(path_ptr) - path = strings.clone(string(path_cstr)) - - return path, nil + return strings.clone(string(path_cstr), allocator) } access :: proc(path: string, mask: int) -> (bool, Error) { diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index 8c8cd7f73..2153b04fd 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -914,7 +914,7 @@ absolute_path_from_handle :: proc(fd: Handle) -> (string, Error) { } @(require_results) -absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { +absolute_path_from_relative :: proc(rel: string, allocator := context.allocator) -> (path: string, err: Error) { rel := rel if rel == "" { rel = "." @@ -929,9 +929,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { } defer _unix_free(rawptr(path_ptr)) - path = strings.clone(string(path_ptr)) - - return path, nil + return strings.clone(string(path_ptr), allocator) } access :: proc(path: string, mask: int) -> (bool, Error) { diff --git a/core/os/os_netbsd.odin b/core/os/os_netbsd.odin index 493527803..e3ba760a4 100644 --- a/core/os/os_netbsd.odin +++ b/core/os/os_netbsd.odin @@ -844,7 +844,7 @@ absolute_path_from_handle :: proc(fd: Handle) -> (path: string, err: Error) { } @(require_results) -absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { +absolute_path_from_relative :: proc(rel: string, allocator := context.allocator) -> (path: string, err: Error) { rel := rel if rel == "" { rel = "." @@ -859,9 +859,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { } defer _unix_free(rawptr(path_ptr)) - path = strings.clone(string(path_ptr)) - - return path, nil + return strings.clone(string(path_ptr), allocator) } access :: proc(path: string, mask: int) -> (bool, Error) { diff --git a/core/os/os_openbsd.odin b/core/os/os_openbsd.odin index 62872d9dc..3c377968c 100644 --- a/core/os/os_openbsd.odin +++ b/core/os/os_openbsd.odin @@ -758,7 +758,7 @@ absolute_path_from_handle :: proc(fd: Handle) -> (string, Error) { } @(require_results) -absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { +absolute_path_from_relative :: proc(rel: string, allocator := context.allocator) -> (path: string, err: Error) { rel := rel if rel == "" { rel = "." @@ -773,9 +773,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) { } defer _unix_free(rawptr(path_ptr)) - path = strings.clone(string(path_ptr)) - - return path, nil + return strings.clone(string(path_ptr), allocator) } access :: proc(path: string, mask: int) -> (bool, Error) { diff --git a/core/time/datetime/constants.odin b/core/time/datetime/constants.odin index 003d4fca4..e24709e49 100644 --- a/core/time/datetime/constants.odin +++ b/core/time/datetime/constants.odin @@ -85,9 +85,9 @@ TZ_Record :: struct { } TZ_Date_Kind :: enum { - NoLeap, + No_Leap, Leap, - MonthWeekDay, + Month_Week_Day, } TZ_Transition_Date :: struct { diff --git a/core/time/timezone/tz_unix.odin b/core/time/timezone/tz_unix.odin index 9fe8ff92c..b3ab0d4cc 100644 --- a/core/time/timezone/tz_unix.odin +++ b/core/time/timezone/tz_unix.odin @@ -11,7 +11,7 @@ local_tz_name :: proc(allocator := context.allocator) -> (name: string, success: local_str, ok := os.lookup_env("TZ", allocator) if !ok { orig_localtime_path := "/etc/localtime" - path, err := os.absolute_path_from_relative(orig_localtime_path) + path, err := os.absolute_path_from_relative(orig_localtime_path, allocator) if err != nil { // If we can't find /etc/localtime, fallback to UTC if err == .ENOENT { @@ -22,11 +22,11 @@ local_tz_name :: proc(allocator := context.allocator) -> (name: string, success: return } - defer delete(path) + defer delete(path, allocator) // FreeBSD makes me sad. if path == orig_localtime_path { - data := os.read_entire_file("/var/db/zoneinfo") or_return + data := os.read_entire_file("/var/db/zoneinfo", allocator) or_return return strings.trim_right_space(string(data)), true } @@ -52,6 +52,8 @@ local_tz_name :: proc(allocator := context.allocator) -> (name: string, success: } if local_str == "" { + delete(local_str) + str, err := strings.clone("UTC", allocator) if err != nil { return } return str, true diff --git a/core/time/timezone/tzdate.odin b/core/time/timezone/tzdate.odin index 672ebbba5..c96f8aab3 100644 --- a/core/time/timezone/tzdate.odin +++ b/core/time/timezone/tzdate.odin @@ -38,6 +38,7 @@ region_destroy :: proc(region: ^datetime.TZ_Region, allocator := context.allocat } +@private region_get_nearest :: proc(region: ^datetime.TZ_Region, tm: time.Time) -> (out: datetime.TZ_Record, success: bool) { if len(region.records) == 0 { return process_rrule(region.rrule, tm) @@ -86,7 +87,7 @@ trans_date_to_seconds :: proc(year: i64, td: datetime.TZ_Transition_Date) -> (se ONE_DAY :: 86_400 #partial switch td.type { - case .MonthWeekDay: + case .Month_Week_Day: year_start := datetime.DateTime{{year, 1, 1}, {0, 0, 0, 0}, nil} year_start_time := time.datetime_to_time(year_start) or_return @@ -115,7 +116,8 @@ trans_date_to_seconds :: proc(year: i64, td: datetime.TZ_Transition_Date) -> (se return } - + +@private process_rrule :: proc(rrule: datetime.TZ_RRule, tm: time.Time) -> (out: datetime.TZ_Record, success: bool) { if !rrule.has_dst { return datetime.TZ_Record{ diff --git a/core/time/timezone/tzif.odin b/core/time/timezone/tzif.odin index dce54a4e7..609cbda73 100644 --- a/core/time/timezone/tzif.odin +++ b/core/time/timezone/tzif.odin @@ -282,7 +282,7 @@ parse_posix_rrule :: proc(str: string) -> (out: datetime.TZ_Transition_Date, idx } return datetime.TZ_Transition_Date{ - type = .NoLeap, + type = .No_Leap, day = u16(day), time = offset, }, i, true @@ -350,7 +350,7 @@ parse_posix_rrule :: proc(str: string) -> (out: datetime.TZ_Transition_Date, idx } return datetime.TZ_Transition_Date{ - type = .MonthWeekDay, + type = .Month_Week_Day, month = u8(month), week = u8(week), day = u16(day), diff --git a/tests/core/time/test_core_time.odin b/tests/core/time/test_core_time.odin index 281b2289a..93bc73789 100644 --- a/tests/core/time/test_core_time.odin +++ b/tests/core/time/test_core_time.odin @@ -455,7 +455,7 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { std_name = "EST", std_offset = -(5 * 60 * 60), std_date = dt.TZ_Transition_Date{ - type = .MonthWeekDay, + type = .Month_Week_Day, month = 3, week = 2, day = 0, @@ -465,7 +465,7 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { dst_name = "EDT", dst_offset = -(4 * 60 * 60), dst_date = dt.TZ_Transition_Date{ - type = .MonthWeekDay, + type = .Month_Week_Day, month = 11, week = 1, day = 0, @@ -484,7 +484,7 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { std_name = "IST", std_offset = (2 * 60 * 60), std_date = dt.TZ_Transition_Date{ - type = .MonthWeekDay, + type = .Month_Week_Day, month = 3, week = 4, day = 4, @@ -494,7 +494,7 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { dst_name = "IDT", dst_offset = (3 * 60 * 60), dst_date = dt.TZ_Transition_Date{ - type = .MonthWeekDay, + type = .Month_Week_Day, month = 10, week = 5, day = 0, @@ -513,7 +513,7 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { std_name = "WART", std_offset = -(4 * 60 * 60), std_date = dt.TZ_Transition_Date{ - type = .NoLeap, + type = .No_Leap, day = 1, time = 0 * 60 * 60, }, @@ -521,7 +521,7 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { dst_name = "WARST", dst_offset = -(3 * 60 * 60), dst_date = dt.TZ_Transition_Date{ - type = .NoLeap, + type = .No_Leap, day = 365, time = 25 * 60 * 60, }, @@ -538,7 +538,7 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { std_name = "WGT", std_offset = -(3 * 60 * 60), std_date = dt.TZ_Transition_Date{ - type = .MonthWeekDay, + type = .Month_Week_Day, month = 3, week = 5, day = 0, @@ -548,7 +548,7 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { dst_name = "WGST", dst_offset = -(2 * 60 * 60), dst_date = dt.TZ_Transition_Date{ - type = .MonthWeekDay, + type = .Month_Week_Day, month = 10, week = 5, day = 0,