diff options
author | Joe <rbo@gmx.us> | 2024-01-23 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-01-23 20:20:20 +0100 |
commit | 18d207ef1777d9c713192f39f671ae1902f8c94a (patch) | |
tree | 4cf77b9c23b1386f436e655a960841e5e143051d /src/c_utils.go | |
parent | good (diff) | |
download | hardflip-18d207ef1777d9c713192f39f671ae1902f8c94a.tar.gz hardflip-18d207ef1777d9c713192f39f671ae1902f8c94a.tar.bz2 hardflip-18d207ef1777d9c713192f39f671ae1902f8c94a.tar.xz hardflip-18d207ef1777d9c713192f39f671ae1902f8c94a.tar.zst hardflip-18d207ef1777d9c713192f39f671ae1902f8c94a.zip |
segv
Diffstat (limited to '')
-rw-r--r-- | src/c_utils.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/c_utils.go b/src/c_utils.go index 72761d8..84479ce 100644 --- a/src/c_utils.go +++ b/src/c_utils.go @@ -60,8 +60,8 @@ import ( // not exist // the first path being checked is $XDG_DATA_HOME then $HOME/.local/share // it returns the full data directory path -func c_get_data_dir() string { - var ptr *string +func c_get_data_dir(ui *HardUI) string { + var ptr string var home string if home = os.Getenv("HOME"); len(home) == 0 { c_die("env variable HOME not defined", nil) @@ -69,18 +69,26 @@ func c_get_data_dir() string { xdg_home := os.Getenv("XDG_DATA_HOME") if len(xdg_home) > 0 { - ptr = &xdg_home + ptr = xdg_home + "/qwe" } else { - ptr = &home - *ptr += "/.local/share" + ptr = home + "/.local/share" } - *ptr += "/" + DATA_DIR_NAME - if _, err := os.Stat(*ptr); os.IsNotExist(err) { - if err := os.MkdirAll(*ptr, os.ModePerm); err != nil { - c_die("could not create path " + *ptr, err) + ptr += "/" + DATA_DIR_NAME + if _, err := os.Stat(ptr); os.IsNotExist(err) { + if err := os.MkdirAll(ptr, os.ModePerm); err != nil { + if ui == nil { + c_die("could not create path " + ptr, err) + } + c_error_mode("could not create path" + ptr, err, ui) } + } else if err != nil { + if ui == nil { + c_die("could read path " + ptr, err) + } + c_error_mode("could read path" + ptr, err, ui) + // FIX: segv } - return *ptr + return ptr } // c_die displays an error string to the stderr fd and exits the program |