utils: add and use homedir_get()

SVN revision: 77663
devs/lucas/wip
Gustavo Sverzut Barbieri 10 years ago
parent 84d381344a
commit 0a4938a4f2
  1. 5
      src/bin/config.c
  2. 19
      src/bin/termiolink.c
  3. 20
      src/bin/utils.c
  4. 2
      src/bin/utils.h

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

@ -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];
if (!homedir_get(homepath, sizeof(homepath)))
return NULL;
eina_str_join(tmppath, sizeof(tmppath), '/', home, relpath);
eina_str_join(tmppath, sizeof(tmppath), '/', homepath, relpath);
return strdup(tmppath);
}

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

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

Loading…
Cancel
Save