aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-08-15 15:44:48 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-08-15 15:44:48 +0200
commit1aedf99b838e96c9008c856ffbb90fe2c0902424 (patch)
tree67a1da6da215a529822a13d685fba6e7f6e0f95b /src
parent712b434cd24914c486921878e5c9241495574aac (diff)
Improve get_executable_path
Diffstat (limited to 'src')
-rw-r--r--src/common/util.odin35
1 files changed, 9 insertions, 26 deletions
diff --git a/src/common/util.odin b/src/common/util.odin
index f0195ca..08a846f 100644
--- a/src/common/util.odin
+++ b/src/common/util.odin
@@ -33,15 +33,11 @@ lookup_in_path :: proc(name: string) -> (string, bool) {
return possibility, true
}
} else {
- possibility := filepath.join(
- elems = {directory, name},
- allocator = context.temp_allocator,
- )
+ possibility := filepath.join(elems = {directory, name}, allocator = context.temp_allocator)
possibility = resolve_home_dir(possibility, context.temp_allocator)
if os.exists(possibility) {
if info, err := os.stat(possibility, context.temp_allocator);
- err == os.ERROR_NONE &&
- (File_Mode_User_Executable & info.mode) != 0 {
+ err == os.ERROR_NONE && (File_Mode_User_Executable & info.mode) != 0 {
return possibility, true
}
}
@@ -67,9 +63,7 @@ resolve_home_dir :: proc(
home := os.get_env("HOME", context.temp_allocator)
if home == "" {
- log.error(
- "could not find $HOME in the environment to be able to resolve ~ in collection paths",
- )
+ log.error("could not find $HOME in the environment to be able to resolve ~ in collection paths")
return path, false
}
@@ -80,18 +74,8 @@ resolve_home_dir :: proc(
when ODIN_OS == .Darwin || ODIN_OS == .Linux || ODIN_OS == .NetBSD {
FILE :: struct {}
- run_executable :: proc(
- command: string,
- stdout: ^[]byte,
- ) -> (
- u32,
- bool,
- []byte,
- ) {
- fp := popen(
- strings.clone_to_cstring(command, context.temp_allocator),
- "r",
- )
+ run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) {
+ fp := popen(strings.clone_to_cstring(command, context.temp_allocator), "r")
if fp == nil {
return 0, false, stdout[0:]
}
@@ -123,13 +107,12 @@ when ODIN_OS == .Darwin || ODIN_OS == .Linux || ODIN_OS == .NetBSD {
}
get_executable_path :: proc(allocator := context.temp_allocator) -> string {
- exe_path, ok := filepath.abs(
- slashpath.dir(os.args[0], context.temp_allocator),
- context.temp_allocator,
- )
+ exe_path, ok := filepath.abs(os.args[0], context.temp_allocator)
+
if !ok {
log.error("Failed to resolve executable path")
return ""
}
- return exe_path
+
+ return filepath.dir(exe_path, allocator)
}