diff options
author | Joe <rbo@gmx.us> | 2023-12-20 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2023-12-20 20:20:20 +0100 |
commit | 126815f9aad4c841ada3c5b4c8db11200b52a8fe (patch) | |
tree | a79f53de45aaef34f4cbb644c3c415556c4cff74 /c_utils.go | |
parent | up (diff) | |
download | hardflip-126815f9aad4c841ada3c5b4c8db11200b52a8fe.tar.gz hardflip-126815f9aad4c841ada3c5b4c8db11200b52a8fe.tar.bz2 hardflip-126815f9aad4c841ada3c5b4c8db11200b52a8fe.tar.xz hardflip-126815f9aad4c841ada3c5b4c8db11200b52a8fe.tar.zst hardflip-126815f9aad4c841ada3c5b4c8db11200b52a8fe.zip |
loop
Diffstat (limited to '')
-rw-r--r-- | c_utils.go | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_utils.go - * Thu, 14 Dec 2023 12:59:16 +0100 + * Wed Dec 20 10:50:12 2023 * Joe * * core funcs @@ -52,6 +52,33 @@ import ( "os" ) +// this function will go get the data folder and try to create it if it does +// 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 + var home string + if home = os.Getenv("HOME"); len(home) == 0 { + c_die("env variable HOME not defined", nil) + } + xdg_home := os.Getenv("XDG_DATA_HOME") + + if len(xdg_home) > 0 { + ptr = &xdg_home + } else { + ptr = &home + *ptr += "/.local/share" + } + *ptr += "/hardflip" + 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) + } + } + return *ptr +} + // c_die displays an error string to the stderr fd and exits the program // with the return code 1 // it takes an optional err argument of the error type as a complement of |