mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-09 13:01:38 -07:00
match user.odin and env.odin to master
This commit is contained in:
+12
-3
@@ -1,11 +1,20 @@
|
||||
package os2
|
||||
|
||||
// get_env gets the value of the environment variable named by the key
|
||||
// get_env retrieves the value of the environment variable named by the key
|
||||
// It returns the value, which will be empty if the variable is not present
|
||||
// To distinguish between an empty value and an unset value, use lookup_env
|
||||
// NOTE: the value will be allocated with the supplied allocator
|
||||
get_env :: proc(key: string, allocator := context.allocator) -> string {
|
||||
value, _ := lookup_env(key, allocator)
|
||||
return value
|
||||
}
|
||||
|
||||
// lookup_env gets the value of the environment variable named by the key
|
||||
// If the variable is found in the environment the value (which can be empty) is returned and the boolean is true
|
||||
// Otherwise the returned value will be empty and the boolean will be false
|
||||
// NOTE: the value will be allocated with the supplied allocator
|
||||
get_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) {
|
||||
return _get_env(key, allocator)
|
||||
lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) {
|
||||
return _lookup_env(key, allocator)
|
||||
}
|
||||
|
||||
// set_env sets the value of the environment variable named by the key
|
||||
|
||||
+19
-21
@@ -4,58 +4,56 @@ import "core:strings"
|
||||
import "core:runtime"
|
||||
|
||||
user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||
found: bool
|
||||
#partial switch ODIN_OS {
|
||||
case .Windows:
|
||||
dir, found = get_env("LocalAppData")
|
||||
if found {
|
||||
dir = get_env("LocalAppData")
|
||||
if dir != "" {
|
||||
dir = strings.clone_safe(dir, allocator) or_return
|
||||
}
|
||||
case .Darwin:
|
||||
dir, found = get_env("HOME")
|
||||
if found {
|
||||
dir = get_env("HOME")
|
||||
if dir != "" {
|
||||
dir = strings.concatenate_safe({dir, "/Library/Caches"}, allocator) or_return
|
||||
}
|
||||
case: // All other UNIX systems
|
||||
dir, found = get_env("XDG_CACHE_HOME")
|
||||
if found {
|
||||
dir, found = get_env("HOME")
|
||||
if !found {
|
||||
dir = get_env("XDG_CACHE_HOME")
|
||||
if dir == "" {
|
||||
dir = get_env("HOME")
|
||||
if dir == "" {
|
||||
return
|
||||
}
|
||||
dir = strings.concatenate_safe({dir, "/.cache"}, allocator) or_return
|
||||
}
|
||||
}
|
||||
if !found || dir == "" {
|
||||
if dir == "" {
|
||||
err = .Invalid_Path
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
user_config_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||
found: bool
|
||||
#partial switch ODIN_OS {
|
||||
case .Windows:
|
||||
dir, found = get_env("AppData")
|
||||
if found {
|
||||
dir = get_env("AppData")
|
||||
if dir != "" {
|
||||
dir = strings.clone_safe(dir, allocator) or_return
|
||||
}
|
||||
case .Darwin:
|
||||
dir, found = get_env("HOME")
|
||||
if found {
|
||||
dir = get_env("HOME")
|
||||
if dir != "" {
|
||||
dir = strings.concatenate_safe({dir, "/Library/Application Support"}, allocator) or_return
|
||||
}
|
||||
case: // All other UNIX systems
|
||||
dir, found = get_env("XDG_CACHE_HOME")
|
||||
if !found {
|
||||
dir, found = get_env("HOME")
|
||||
if !found {
|
||||
dir = get_env("XDG_CACHE_HOME")
|
||||
if dir == "" {
|
||||
dir = get_env("HOME")
|
||||
if dir == "" {
|
||||
return
|
||||
}
|
||||
dir = strings.concatenate_safe({dir, "/.config"}, allocator) or_return
|
||||
}
|
||||
}
|
||||
if !found || dir == "" {
|
||||
if dir == "" {
|
||||
err = .Invalid_Path
|
||||
}
|
||||
return
|
||||
@@ -67,7 +65,7 @@ user_home_dir :: proc() -> (dir: string, err: Error) {
|
||||
case .Windows:
|
||||
env = "USERPROFILE"
|
||||
}
|
||||
if v, found := get_env(env); found {
|
||||
if v := get_env(env); v != "" {
|
||||
return v, nil
|
||||
}
|
||||
return "", .Invalid_Path
|
||||
|
||||
Reference in New Issue
Block a user