mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-06 02:34:05 +00:00
tweaks per laytan suggestions
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -85,9 +85,9 @@ TZ_Record :: struct {
|
||||
}
|
||||
|
||||
TZ_Date_Kind :: enum {
|
||||
NoLeap,
|
||||
No_Leap,
|
||||
Leap,
|
||||
MonthWeekDay,
|
||||
Month_Week_Day,
|
||||
}
|
||||
|
||||
TZ_Transition_Date :: struct {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user