summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_vpath_xdg.c
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2018-08-20 12:57:57 -0400
committerMike Blumenkrantz <zmike@samsung.com>2018-08-20 12:57:57 -0400
commit7968a0d0b979493774372fe07bcff0559233e8be (patch)
tree67fa9395cdafff487fd49e2d47d3671a60289bf4 /src/lib/eina/eina_vpath_xdg.c
parente31ce7b28711c43d37fb5d8469a236e6a17460ab (diff)
move efreet xdg envvars to eina
Summary: The contents of the XDG_ env vars are also usefull for eina subsystems, thus we should init those env vars here. Depends on D6751 Reviewers: zmike, stefan_schmidt, #committers Reviewed By: zmike, #committers Subscribers: #reviewers, cedric, #committers, zmike Tags: #efl Differential Revision: https://phab.enlightenment.org/D6744
Diffstat (limited to 'src/lib/eina/eina_vpath_xdg.c')
-rw-r--r--src/lib/eina/eina_vpath_xdg.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/lib/eina/eina_vpath_xdg.c b/src/lib/eina/eina_vpath_xdg.c
new file mode 100644
index 0000000..6a1d4d8
--- /dev/null
+++ b/src/lib/eina/eina_vpath_xdg.c
@@ -0,0 +1,83 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <sys/types.h>
6#include <pwd.h>
7
8#include <Eina.h>
9
10#include "eina_internal.h"
11#include "eina_private.h"
12
13void
14eina_xdg_env_init(void)
15{
16 char buf[PATH_MAX];
17 char *s;
18 const char *home;
19 Eina_Vpath_Interface_User user;
20
21 home = eina_vpath_resolve("(:home:)/");
22
23 memset(&user, 0, sizeof(Eina_Vpath_Interface_User));
24
25# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
26# define ENV_HOME_SET(_env, _dir, _meta) \
27 if ((getuid() != geteuid()) || (!(s = getenv(_env)))) { \
28 snprintf(buf, sizeof(buf), "%s/"_dir, home); \
29 s = buf; \
30 } \
31 (&user)->_meta = s;
32#else
33# define ENV_HOME_SET(_env, _dir, _meta) \
34 if (!(s = getenv(_env))) { \
35 snprintf(buf, sizeof(buf), "%s/"_dir, home); \
36 s = buf; \
37 } \
38 (&user)->_meta = s;
39#endif
40 // $XDG_DESKTOP_DIR="$HOME/Desktop"
41 ENV_HOME_SET("XDG_DESKTOP_DIR", "Desktop", desktop);
42 // $XDG_DOCUMENTS_DIR="$HOME/Documents"
43 ENV_HOME_SET("XDG_DOCUMENTS_DIR", "Documents", documents);
44 // $XDG_DOWNLOAD_DIR="$HOME/Downloads"
45 ENV_HOME_SET("XDG_DOWNLOAD_DIR", "Downloads", downloads);
46 // $XDG_MUSIC_DIR="$HOME/Music"
47 ENV_HOME_SET("XDG_MUSIC_DIR", "Music", music);
48 // $XDG_PICTURES_DIR="$HOME/Pictures"
49 ENV_HOME_SET("XDG_PICTURES_DIR", "Pictures", pictures);
50 // $XDG_PUBLICSHARE_DIR="$HOME/Public"
51 ENV_HOME_SET("XDG_PUBLIC_DIR", "Public", pub);
52 // $XDG_TEMPLATES_DIR="$HOME/.Templates"
53 ENV_HOME_SET("XDG_TEMPLATES_DIR", ".Templates", templates);
54 // $XDG_VIDEOS_DIR="$HOME/Videos"
55 ENV_HOME_SET("XDG_VIDEOS_DIR", "Videos", videos);
56 // $XDG_DATA_HOME defines the base directory relative to which user
57 // specific data files should be stored. If $XDG_DATA_HOME is either
58 // not set or empty, a default equal to $HOME/.local/share should be
59 // used.
60 ENV_HOME_SET("XDG_DATA_HOME", ".local/share", data);
61 ENV_HOME_SET("XDG_TMP_HOME", ".local/tmp", tmp);
62 // $XDG_CONFIG_HOME defines the base directory relative to which user
63 // specific configuration files should be stored. If $XDG_CONFIG_HOME
64 // is either not set or empty, a default equal to $HOME/.config should
65 // be used.
66 ENV_HOME_SET("XDG_CONFIG_HOME", ".config", config);
67 // $XDG_CACHE_HOME defines the base directory relative to which
68 // user specific non-essential data files should be stored. If
69 // $XDG_CACHE_HOME is either not set or empty, a default equal to
70 // $HOME/.cache should be used.
71 ENV_HOME_SET("XDG_CACHE_HOME", ".cache", cache);
72
73#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
74 if ((getuid() != geteuid()) || (!(s = getenv("XDG_RUNTIME_DIR"))))
75#else
76 if (!(s = getenv("XDG_RUNTIME_DIR")))
77#endif
78 user.run = NULL;
79 else
80 user.run = s;
81
82 eina_vpath_interface_user_set(&user);
83}