summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-04-17 16:39:52 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-04-17 17:44:12 +0100
commitf81dfbfe644b8ff6c8c08516ee2ee671d83f2f44 (patch)
treef377c3eaf5f709e3cf1f77770842b6bdea3a62b0 /src/lib/eina
parenta30caf333eda83bb83a8083c34ca4dccfabf6b10 (diff)
eina vpath - clear up vpath to handle env vars that are too big as fatal
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_vpath_xdg.c70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/lib/eina/eina_vpath_xdg.c b/src/lib/eina/eina_vpath_xdg.c
index 9d1c320..094f5d2 100644
--- a/src/lib/eina/eina_vpath_xdg.c
+++ b/src/lib/eina/eina_vpath_xdg.c
@@ -13,62 +13,65 @@
13void 13void
14eina_xdg_env_init(void) 14eina_xdg_env_init(void)
15{ 15{
16 char *s; 16 char home[PATH_MAX], *s;
17 char home[PATH_MAX];
18 Eina_Vpath_Interface_User user; 17 Eina_Vpath_Interface_User user;
19 18
20 eina_vpath_resolve_snprintf(home, sizeof(home), "(:home:)/"); 19 eina_vpath_resolve_snprintf(home, sizeof(home), "(:home:)/");
21
22 memset(&user, 0, sizeof(Eina_Vpath_Interface_User)); 20 memset(&user, 0, sizeof(Eina_Vpath_Interface_User));
23 21
24#ifdef _WIN32 22#define FATAL_SNPRINTF(_buf, _err, _fmt, ...) \
23 do { \
24 if ((size_t)snprintf(_buf, sizeof(_buf), _fmt, ## __VA_ARGS__) >= (sizeof(_buf) - 1)) { \
25 fprintf(stderr, _err"\n", _buf); \
26 abort(); \
27 } \
28 } while (0)
25 29
30#ifdef _WIN32
26# define ENV_SET(_env, _dir, _meta) \ 31# define ENV_SET(_env, _dir, _meta) \
27 char _meta [PATH_MAX + 128]; \ 32 char _meta[PATH_MAX + 128]; \
28 char *_meta##env = _env; \ 33 if (_env) { \
29 char *_meta##dir = _dir; \ 34 s = getenv(_env); \
30 if (_meta##env) \ 35 if (!s) s = home; \
31 strcpy(_meta, getenv(_meta##env)); \ 36 } else s = home; \
32 else \ 37 if (_dir) FATAL_SNPRINTF(_meta, "vpath string '%s' truncated - fatal", "%s\\%s", s, _dir); \
33 strcpy(_meta, home); \ 38 else FATAL_SNPRINTF(_meta, "vpath string '%s' truncated - fatal", "%s\\", s); \
34 if (_meta##dir) \ 39 (&user)->_meta = _meta;
35 strcat(_meta, _meta##dir); \
36 s = _meta; \
37 (&user)->_meta = s;
38 40
39 ENV_SET(NULL, "\\Desktop", desktop); 41 ENV_SET(NULL, "Desktop", desktop);
40 ENV_SET(NULL, "\\Documents", documents); 42 ENV_SET(NULL, "Documents", documents);
41 ENV_SET(NULL, "\\Downloads", downloads); 43 ENV_SET(NULL, "Downloads", downloads);
42 ENV_SET(NULL, "\\Music", music); 44 ENV_SET(NULL, "Music", music);
43 ENV_SET(NULL, "\\Pictures", pictures); 45 ENV_SET(NULL, "Pictures", pictures);
44 ENV_SET("CommonProgramFiles", NULL, pub); 46 ENV_SET("CommonProgramFiles", NULL, pub);
45 ENV_SET("APPDATA", "\\Microsoft\\Windows\\Templates", templates); 47 ENV_SET("APPDATA", "Microsoft\\Windows\\Templates", templates);
46 ENV_SET(NULL, "\\Videos", videos); 48 ENV_SET(NULL, "Videos", videos);
47 ENV_SET("LOCALAPPDATA", NULL, data); 49 ENV_SET("LOCALAPPDATA", NULL, data);
48 ENV_SET("LOCALAPPDATA", "\\Temp", tmp); 50 ENV_SET("LOCALAPPDATA", "Temp", tmp);
49 ENV_SET("APPDATA", NULL, config); 51 ENV_SET("APPDATA", NULL, config);
50 ENV_SET("LOCALAPPDATA", NULL, cache); 52 ENV_SET("LOCALAPPDATA", NULL, cache);
51 ENV_SET("APPDATA", NULL, run); 53 if (!(s = getenv("APPDATA")))
52 54 user.run = NULL;
55 else
56 user.run = s;
53#else /* _WIN32 */ 57#else /* _WIN32 */
54
55# if defined(HAVE_GETUID) && defined(HAVE_GETEUID) 58# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
56# define ENV_HOME_SET(_env, _dir, _meta) \ 59# define ENV_HOME_SET(_env, _dir, _meta) \
57 char _meta [PATH_MAX + 128]; \ 60 char _meta [PATH_MAX + 128]; \
58 if ((getuid() != geteuid()) || (!(s = getenv(_env)))) { \ 61 if ((getuid() != geteuid()) || (!(s = getenv(_env)))) { \
59 snprintf(_meta, sizeof(_meta), "%s/"_dir, home); \ 62 FATAL_SNPRINTF(_meta, "vpath string '%s' truncated - fatal", "%s/"_dir, home); \
60 s = _meta; \ 63 s = _meta; \
61 } \ 64 } \
62 (&user)->_meta = s; 65 (&user)->_meta = s;
63#else 66# else
64# define ENV_HOME_SET(_env, _dir, _meta) \ 67# define ENV_HOME_SET(_env, _dir, _meta) \
65 char _meta [PATH_MAX + 128]; \ 68 char _meta [PATH_MAX + 128]; \
66 if (!(s = getenv(_env))) { \ 69 if (!(s = getenv(_env))) { \
67 snprintf(_meta, sizeof(_meta), "%s/"_dir, home); \ 70 FATAL_SNPRINTF(_meta, "vpath string '%s' truncated - fatal", "%s/"_dir, home); \
68 s = _meta; \ 71 s = _meta; \
69 } \ 72 } \
70 (&user)->_meta = s; 73 (&user)->_meta = s;
71#endif 74# endif
72 // $XDG_DESKTOP_DIR="$HOME/Desktop" 75 // $XDG_DESKTOP_DIR="$HOME/Desktop"
73 ENV_HOME_SET("XDG_DESKTOP_DIR", "Desktop", desktop); 76 ENV_HOME_SET("XDG_DESKTOP_DIR", "Desktop", desktop);
74 // $XDG_DOCUMENTS_DIR="$HOME/Documents" 77 // $XDG_DOCUMENTS_DIR="$HOME/Documents"
@@ -102,15 +105,14 @@ eina_xdg_env_init(void)
102 // $HOME/.cache should be used. 105 // $HOME/.cache should be used.
103 ENV_HOME_SET("XDG_CACHE_HOME", ".cache", cache); 106 ENV_HOME_SET("XDG_CACHE_HOME", ".cache", cache);
104 107
105#if defined(HAVE_GETUID) && defined(HAVE_GETEUID) 108# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
106 if ((getuid() != geteuid()) || (!(s = getenv("XDG_RUNTIME_DIR")))) 109 if ((getuid() != geteuid()) || (!(s = getenv("XDG_RUNTIME_DIR"))))
107#else 110# else
108 if (!(s = getenv("XDG_RUNTIME_DIR"))) 111 if (!(s = getenv("XDG_RUNTIME_DIR")))
109#endif 112# endif
110 user.run = NULL; 113 user.run = NULL;
111 else 114 else
112 user.run = s; 115 user.run = s;
113
114#endif /* _WIN32 */ 116#endif /* _WIN32 */
115 117
116 eina_vpath_interface_user_set(&user); 118 eina_vpath_interface_user_set(&user);