okra pushed a commit to branch master.

http://git.enlightenment.org/apps/ephoto.git/commit/?id=ef805cefa9c6378d75e23c22b437d098114945b7

commit ef805cefa9c6378d75e23c22b437d098114945b7
Author: Stephen 'Okra' Houston <smhousto...@gmail.com>
Date:   Wed Mar 29 16:12:50 2017 -0500

    Ephoto: Fix use of stat/lstat, use eina_environment to get HOME and tmp 
dirs.
---
 src/bin/ephoto_config.c            |  4 ++--
 src/bin/ephoto_directory_browser.c |  4 ++--
 src/bin/ephoto_file.c              | 11 +++++-----
 src/bin/ephoto_ipc.c               | 42 +++++++++-----------------------------
 src/bin/ephoto_main.c              |  2 +-
 src/bin/ephoto_scale.c             |  2 +-
 src/bin/ephoto_single_browser.c    |  2 +-
 src/bin/ephoto_thumb_browser.c     |  4 ++--
 8 files changed, 24 insertions(+), 47 deletions(-)

diff --git a/src/bin/ephoto_config.c b/src/bin/ephoto_config.c
index 3ebcb3a..5edb491 100644
--- a/src/bin/ephoto_config.c
+++ b/src/bin/ephoto_config.c
@@ -19,7 +19,7 @@ _config_save_cb(void *data, Evas_Object *obj EINA_UNUSED,
    if (!strcmp(text, _("Root Directory")))
       path = "/";
    else if (!strcmp(text, _("Home Directory")))
-      path = getenv("HOME");
+      path = eina_environment_home_get();
    else if (!strcmp(text, _("Last Open Directory")))
       path = "Last";
    else
@@ -778,7 +778,7 @@ ephoto_config_init(Ephoto *ephoto)
          ephoto->config->window_height = 500*elm_config_scale_get();
          ephoto->config->fsel_hide = 0;
           ephoto->config->lpane_size = .15;
-         ephoto->config->open = eina_stringshare_add(getenv("HOME"));
+         ephoto->config->open = 
eina_stringshare_add(eina_environment_home_get());
          ephoto->config->prompts = 1;
          ephoto->config->drop = 0;
           ephoto->config->movess = 1;
diff --git a/src/bin/ephoto_directory_browser.c 
b/src/bin/ephoto_directory_browser.c
index 39898ed..cecdceb 100644
--- a/src/bin/ephoto_directory_browser.c
+++ b/src/bin/ephoto_directory_browser.c
@@ -473,7 +473,7 @@ _dir_go_trash(void *data, Evas_Object *obj EINA_UNUSED,
 
    eina_stringshare_replace(&db->back_directory,
        db->ephoto->config->directory);
-   snprintf(path, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
+   snprintf(path, PATH_MAX, "%s/.config/ephoto/trash", 
eina_environment_home_get());
    if (!ecore_file_exists(path))
       ecore_file_mkpath(path);
    db->thumbs_only = 0;
@@ -607,7 +607,7 @@ _fsel_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
    if (info->button != 3)
       return;
 
-   snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
+   snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", 
eina_environment_home_get());
 
    if (item)
      elm_genlist_item_selected_set(item, EINA_TRUE);
diff --git a/src/bin/ephoto_file.c b/src/bin/ephoto_file.c
index a9938a3..7e2b13e 100644
--- a/src/bin/ephoto_file.c
+++ b/src/bin/ephoto_file.c
@@ -728,7 +728,7 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
    const char *file;
    char destination[PATH_MAX];
 
-   snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
+   snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", 
eina_environment_home_get());
    if (!ecore_file_exists(destination))
       ecore_file_mkpath(destination);
 
@@ -743,11 +743,10 @@ _delete_thread_cb(void *data, Ecore_Thread *et 
EINA_UNUSED)
             char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX];
             int ret;
              struct stat s;
-
 #ifdef _WIN32
-             if (stat(file, &s))
+             if (stat(file, &s) == 0)
 #else
-             if (lstat(file, &s))
+             if (lstat(file, &s) == 0)
 #endif
                {
                   if (S_ISLNK(s.st_mode))
@@ -808,7 +807,7 @@ _delete_dir_thread_cb(void *data, Ecore_Thread *et 
EINA_UNUSED)
    const char *dir = eina_list_data_get(ephoto->file_pos);
    char destination[PATH_MAX];
 
-   snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
+   snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", 
eina_environment_home_get());
 
    if (!ecore_file_exists(destination))
       ecore_file_mkpath(destination);
@@ -868,7 +867,7 @@ _empty_trash_thread_cb(void *data, Ecore_Thread *th 
EINA_UNUSED)
    const char *file;
    char trash[PATH_MAX];
 
-   snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
+   snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", 
eina_environment_home_get());
 
    if (!ephoto->file_pos)
       ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0);
diff --git a/src/bin/ephoto_ipc.c b/src/bin/ephoto_ipc.c
index a171b60..be1084f 100644
--- a/src/bin/ephoto_ipc.c
+++ b/src/bin/ephoto_ipc.c
@@ -18,42 +18,20 @@ int
 e_ipc_init(void)
 {
    char buf[4096], buf3[4096];
-   const char *tmp, *user, *base;
+   const char *tmp, *user, *base = NULL;
    int pid, trynum = 0, id1 = 0;
 
    tmp = eina_environment_tmp_get();
-   if (!tmp) tmp = "/tmp";
-   base = tmp;
-
-   tmp = getenv("XDG_RUNTIME_DIR");
-   if (tmp)
-     {
-        if (ecore_file_exists(tmp))
-          {
-             if (ecore_file_is_dir(tmp) && ecore_file_can_write(tmp))
-               base = tmp;
-             else
-               ERR("XDG_RUNTIME_DIR of '%s' failed permissions check", tmp);
-          }
-        else
-          ERR("XDG_RUNTIME_DIR of '%s' cannot be accessed", tmp);
-     }
-
-   tmp = getenv("SD_USER_SOCKETS_DIR");
-   if (tmp)
-     {
-        if (ecore_file_exists(tmp))
-          {
-             if (ecore_file_is_dir(tmp) && ecore_file_can_write(tmp))
-               base = tmp;
-             else
-               ERR("SD_USER_SOCKETS_DIR of '%s' failed permissions check", 
tmp);
-          }
-        else
-          ERR("SD_USER_SOCKETS_DIR of '%s' cannot be accessed", tmp);
-     }
-
+   if (ecore_file_is_dir(tmp) && ecore_file_can_write(tmp))
+     base = tmp;
+   else
+     ERR("Temp dir could not be accessed");
+
+#ifdef _WIN32
+   user = getenv("USERNAME");
+#else
    user = getenv("USER");
+#endif
 
    setenv("EPHOTO_IPC_SOCKET", "", 1);
 
diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c
index e4be4be..f23162a 100644
--- a/src/bin/ephoto_main.c
+++ b/src/bin/ephoto_main.c
@@ -561,7 +561,7 @@ ephoto_window_add(const char *path)
             if (getcwd(buf, sizeof(buf)))
                path = buf;
             else
-               path = getenv("HOME");
+               path = eina_environment_home_get();
          }
      }
 
diff --git a/src/bin/ephoto_scale.c b/src/bin/ephoto_scale.c
index d3f3056..42650c2 100644
--- a/src/bin/ephoto_scale.c
+++ b/src/bin/ephoto_scale.c
@@ -195,7 +195,7 @@ ephoto_scale_add(Ephoto *ephoto, Evas_Object *main, 
Evas_Object *parent,
    es->parent = parent;
    es->image = image;
 
-   snprintf(buf, PATH_MAX, "%s/.config/ephoto/temp.%s", getenv("HOME"),
+   snprintf(buf, PATH_MAX, "%s/.config/ephoto/temp.%s", 
eina_environment_home_get(),
        strrchr(file, '.')+1);
    es->tmp_file = eina_stringshare_add(buf);
    if (ecore_file_exists(es->tmp_file))
diff --git a/src/bin/ephoto_single_browser.c b/src/bin/ephoto_single_browser.c
index 16df84a..27bdbc1 100644
--- a/src/bin/ephoto_single_browser.c
+++ b/src/bin/ephoto_single_browser.c
@@ -2084,7 +2084,7 @@ _ephoto_main_del(void *data, Evas *e EINA_UNUSED, 
Evas_Object *obj EINA_UNUSED,
    if (sb->edit_main)
      evas_object_del(sb->edit_main);
    sb->edit_main = NULL;
-   snprintf(tmp_path, PATH_MAX, "%s/.config/ephoto/", getenv("HOME"));
+   snprintf(tmp_path, PATH_MAX, "%s/.config/ephoto/", 
eina_environment_home_get());
    tmps = eina_file_stat_ls(tmp_path);
    EINA_ITERATOR_FOREACH(tmps, info)
    {
diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c
index 9128763..bfdacc3 100644
--- a/src/bin/ephoto_thumb_browser.c
+++ b/src/bin/ephoto_thumb_browser.c
@@ -945,7 +945,7 @@ _grid_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
           return;
      }
 
-   snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
+   snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", 
eina_environment_home_get());
 
    if (item)
      {
@@ -1724,7 +1724,7 @@ _ephoto_main_key_down(void *data, Evas *e EINA_UNUSED, 
Evas_Object *obj EINA_UNU
              char *trash;
 
              snprintf(path, PATH_MAX, "%s/.config/ephoto/trash",
-                 getenv("HOME"));
+                 eina_environment_home_get());
              trash = strdup(path);
              if ((strlen(trash)) == (strlen(tb->ephoto->config->directory)))
                {

-- 


Reply via email to