utils: add and use homedir_get()

SVN revision: 77663
This commit is contained in:
Gustavo Sverzut Barbieri 2012-10-09 17:20:27 +00:00
parent 84d381344a
commit 0a4938a4f2
4 changed files with 30 additions and 16 deletions

View File

@ -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");

View File

@ -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);
}

View File

@ -1,5 +1,7 @@
#include "private.h"
#include "utils.h"
#include <unistd.h>
#include <pwd.h>
#include <Edje.h>
@ -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)
{

View File

@ -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);