aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-10-09 17:20:27 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-10-09 17:20:27 +0000
commit0a4938a4f28c897a80bbb33b83233ffac4b79158 (patch)
tree16d1744ca4c6f1b1f5e84246c79e483ff55dbf2f /src
parentbig time improvement: relative paths: ~/file, ./file and ../file (diff)
downloadterminology-0a4938a4f28c897a80bbb33b83233ffac4b79158.tar.gz
utils: add and use homedir_get()
SVN revision: 77663
Diffstat (limited to 'src')
-rw-r--r--src/bin/config.c5
-rw-r--r--src/bin/termiolink.c19
-rw-r--r--src/bin/utils.c20
-rw-r--r--src/bin/utils.h2
4 files changed, 30 insertions, 16 deletions
diff --git a/src/bin/config.c b/src/bin/config.c
index faa29ca..c0b026f 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 f3f9c75..c1e58c1 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];
+
+ 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);
}
diff --git a/src/bin/utils.c b/src/bin/utils.c
index 215be61..316c0f7 100644
--- a/src/bin/utils.c
+++ b/src/bin/utils.c
@@ -1,5 +1,7 @@
#include "private.h"
#include "utils.h"
+#include <unistd.h>
+#include <pwd.h>
#include <Edje.h>
@@ -52,6 +54,24 @@ theme_auto_reload_enable(Evas_Object *edje)
}
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)
{
if (casestartswith(str, "http://") ||
diff --git a/src/bin/utils.h b/src/bin/utils.h
index e26c403..c79e667 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);