diff --git a/src/bin/config.c b/src/bin/config.c index faa29cad..c0b026f7 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -20,8 +20,9 @@ _config_home_get(void) if (v) eina_strlcpy(path, v, sizeof(path)); else { - v = getenv("HOME"); - if (v) snprintf(path, sizeof(path), "%s/.config", v); + char homepath[PATH_MAX]; + if (homedir_get(homepath, sizeof(homepath))) + snprintf(path, sizeof(path), "%s/.config", homepath); else { if (!v) v = getenv("TMP"); diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c index f3f9c75c..c1e58c15 100644 --- a/src/bin/termiolink.c +++ b/src/bin/termiolink.c @@ -58,21 +58,12 @@ _cwd_path_get(const Evas_Object *obj, const char *relpath) static char * _home_path_get(const Evas_Object *obj __UNUSED__, const char *relpath) { - char tmppath[PATH_MAX]; - const char *home = getenv("HOME"); - if (!home) - { - uid_t uid = getuid(); - struct passwd *pw = getpwuid(uid); - if (pw) home = pw->pw_dir; - } - if (!home) - { - ERR("Could not get $HOME"); - return NULL; - } + char tmppath[PATH_MAX], homepath[PATH_MAX]; - eina_str_join(tmppath, sizeof(tmppath), '/', home, relpath); + if (!homedir_get(homepath, sizeof(homepath))) + return NULL; + + eina_str_join(tmppath, sizeof(tmppath), '/', homepath, relpath); return strdup(tmppath); } diff --git a/src/bin/utils.c b/src/bin/utils.c index 215be619..316c0f73 100644 --- a/src/bin/utils.c +++ b/src/bin/utils.c @@ -1,5 +1,7 @@ #include "private.h" #include "utils.h" +#include +#include #include @@ -51,6 +53,24 @@ theme_auto_reload_enable(Evas_Object *edje) (edje, "edje,change,file", "edje", theme_reload_cb, NULL); } +Eina_Bool +homedir_get(char *buf, size_t size) +{ + const char *home = getenv("HOME"); + if (!home) + { + uid_t uid = getuid(); + struct passwd *pw = getpwuid(uid); + if (pw) home = pw->pw_dir; + } + if (!home) + { + ERR("Could not get $HOME"); + return EINA_FALSE; + } + return eina_strlcpy(buf, home, size) < size; +} + Eina_Bool link_is_protocol(const char *str) { diff --git a/src/bin/utils.h b/src/bin/utils.h index e26c403c..c79e6673 100644 --- a/src/bin/utils.h +++ b/src/bin/utils.h @@ -8,6 +8,8 @@ Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group void theme_reload(Evas_Object *edje); void theme_auto_reload_enable(Evas_Object *edje); +Eina_Bool homedir_get(char *buf, size_t size); + Eina_Bool link_is_protocol(const char *str); Eina_Bool link_is_url(const char *str); Eina_Bool link_is_email(const char *str);