From a60d4d8f7478453ef82c51a5b02cb1fc1f8ff814 Mon Sep 17 00:00:00 2001 From: "F. Duncanh" Date: Tue, 28 Nov 2023 11:41:16 -0500 Subject: [PATCH] uxplay.cpp refactor to split off get_homedir() --- uxplay.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/uxplay.cpp b/uxplay.cpp index 3c29fae..c64cd7a 100644 --- a/uxplay.cpp +++ b/uxplay.cpp @@ -480,6 +480,19 @@ static int parse_hw_addr (std::string str, std::vector &hw_addr) { return 0; } +const char *get_homedir() { + const char *homedir = getenv("XDG_CONFIG_HOMEDIR"); + if (homedir == NULL) { + homedir = getenv("HOME"); + } +#ifndef _WIN32 + if (homedir == NULL){ + homedir = getpwuid(getuid())->pw_dir; + } +#endif + return homedir; +} + static std::string find_uxplay_config_file() { std::string no_config_file = ""; const char *homedir = NULL; @@ -491,15 +504,7 @@ static std::string find_uxplay_config_file() { config0 = uxplayrc; if (stat(config0.c_str(), &sb) == 0) return config0; } - homedir = getenv("XDG_CONFIG_HOMEDIR"); - if (homedir == NULL) { - homedir = getenv("HOME"); - } -#ifndef _WIN32 - if (homedir == NULL){ - homedir = getpwuid(getuid())->pw_dir; - } -#endif + homedir = get_homedir(); if (homedir) { config1 = homedir; config1.append("/.uxplayrc");