summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2015-08-13 08:14:32 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-08-21 17:10:39 +0200
commit743e6a1a24b3e2af1e3e7255cd74126f53bc85e5 (patch)
treeb02810bbf0a875969977bf6fbdcf5e4db4838d45
parent33227fc15d7fe2dcf7bdb7a69b3c46034d3c43b1 (diff)
eina: use new eina_file_path_join API
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/lib/eina/eina_module.c14
-rw-r--r--src/lib/eina/eina_prefix.c45
2 files changed, 21 insertions, 38 deletions
diff --git a/src/lib/eina/eina_module.c b/src/lib/eina/eina_module.c
index 1c2075ae25..2cfcde7d38 100644
--- a/src/lib/eina/eina_module.c
+++ b/src/lib/eina/eina_module.c
@@ -82,14 +82,6 @@ static int EINA_MODULE_LOG_DOM = -1;
82#endif 82#endif
83#define DBG(...) EINA_LOG_DOM_DBG(EINA_MODULE_LOG_DOM, __VA_ARGS__) 83#define DBG(...) EINA_LOG_DOM_DBG(EINA_MODULE_LOG_DOM, __VA_ARGS__)
84 84
85#ifdef _WIN32
86# define SEP_C '\\'
87# define SEP_S "\\"
88#else
89# define SEP_C '/'
90# define SEP_S "/"
91#endif
92
93#define EINA_MODULE_SYMBOL_INIT "__eina_module_init" 85#define EINA_MODULE_SYMBOL_INIT "__eina_module_init"
94#define EINA_MODULE_SYMBOL_SHUTDOWN "__eina_module_shutdown" 86#define EINA_MODULE_SYMBOL_SHUTDOWN "__eina_module_shutdown"
95 87
@@ -149,7 +141,7 @@ static void _dir_list_cb(const char *name, const char *path, void *data)
149 141
150 file = alloca(sizeof (char) * length); 142 file = alloca(sizeof (char) * length);
151 143
152 snprintf(file, length, "%s" SEP_S "%s", path, name); 144 snprintf(file, length, "%s" EINA_PATH_SEP_S "%s", path, name);
153 m = eina_module_new(file); 145 m = eina_module_new(file);
154 if (!m) 146 if (!m)
155 { 147 {
@@ -174,7 +166,7 @@ static void _dir_arch_list_cb(const char *name, const char *path, void *data)
174 sizeof(SHARED_LIB_SUFFIX) + 1; 166 sizeof(SHARED_LIB_SUFFIX) + 1;
175 167
176 file = alloca(length); 168 file = alloca(length);
177 snprintf(file, length, "%s" SEP_S "%s" SEP_S "%s" SEP_S "module" SHARED_LIB_SUFFIX, 169 snprintf(file, length, "%s" EINA_PATH_SEP_S "%s" EINA_PATH_SEP_S "%s" EINA_PATH_SEP_S "module" SHARED_LIB_SUFFIX,
178 path, name, (char *)(cb_data->data)); 170 path, name, (char *)(cb_data->data));
179 m = eina_module_new(file); 171 m = eina_module_new(file);
180 if (!m) 172 if (!m)
@@ -424,7 +416,7 @@ EAPI char *eina_module_symbol_path_get(const void *symbol, const char *sub_dir)
424 416
425 if (dladdr(symbol, &eina_dl)) 417 if (dladdr(symbol, &eina_dl))
426 { 418 {
427 char *pos = strrchr(eina_dl.dli_fname, SEP_C); 419 char *pos = strrchr(eina_dl.dli_fname, EINA_PATH_SEP_C);
428 if (pos) 420 if (pos)
429 { 421 {
430 char *path; 422 char *path;
diff --git a/src/lib/eina/eina_prefix.c b/src/lib/eina/eina_prefix.c
index 7428ec377f..a01b5fa7ff 100644
--- a/src/lib/eina/eina_prefix.c
+++ b/src/lib/eina/eina_prefix.c
@@ -54,6 +54,7 @@
54#include "eina_alloca.h" 54#include "eina_alloca.h"
55#include "eina_log.h" 55#include "eina_log.h"
56#include "eina_str.h" 56#include "eina_str.h"
57#include "eina_file.h"
57 58
58/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ 59/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
59#include "eina_safety_checks.h" 60#include "eina_safety_checks.h"
@@ -61,12 +62,8 @@
61 62
62#ifdef _WIN32 63#ifdef _WIN32
63# define PSEP_C ';' 64# define PSEP_C ';'
64# define DSEP_C '\\'
65# define DSEP_S "\\"
66#else 65#else
67# define PSEP_C ':' 66# define PSEP_C ':'
68# define DSEP_C '/'
69# define DSEP_S "/"
70#endif /* _WIN32 */ 67#endif /* _WIN32 */
71 68
72/*============================================================================* 69/*============================================================================*
@@ -122,12 +119,6 @@ struct _Eina_Prefix
122static int _eina_prefix_log_dom = -1; 119static int _eina_prefix_log_dom = -1;
123 120
124static int 121static int
125_path_join(char *buf, int bufsize, const char *base, const char *extra)
126{
127 return eina_str_join(buf, bufsize, DSEP_C, base, extra);
128}
129
130static int
131_path_join_multiple(char *buf, int bufsize, ...) 122_path_join_multiple(char *buf, int bufsize, ...)
132{ 123{
133 va_list ap; 124 va_list ap;
@@ -154,7 +145,7 @@ _path_join_multiple(char *buf, int bufsize, ...)
154 } 145 }
155 146
156 if (used > 0) 147 if (used > 0)
157 buf[used] = DSEP_C; 148 buf[used] = EINA_PATH_SEP_C;
158 149
159 memcpy(buf + used + seplen, comp, complen); 150 memcpy(buf + used + seplen, comp, complen);
160 used += complen + seplen; 151 used += complen + seplen;
@@ -171,7 +162,7 @@ _path_sep_fix(char *buf)
171 for (; *buf != '\0'; buf++) 162 for (; *buf != '\0'; buf++)
172 { 163 {
173 if (*buf == '/') 164 if (*buf == '/')
174 *buf = DSEP_C; 165 *buf = EINA_PATH_SEP_C;
175 } 166 }
176#else 167#else
177 (void)buf; 168 (void)buf;
@@ -184,7 +175,7 @@ _path_absolute_check(const char *path)
184#ifdef _WIN32 175#ifdef _WIN32
185 return evil_path_is_absolute(path); 176 return evil_path_is_absolute(path);
186#else 177#else
187 return (path[0] == DSEP_C); 178 return (path[0] == EINA_PATH_SEP_C);
188#endif 179#endif
189} 180}
190 181
@@ -196,7 +187,7 @@ _fallback(Eina_Prefix *pfx, const char *pkg_bin, const char *pkg_lib,
196 187
197 STRDUP_REP(pfx->prefix_path, pkg_bin); 188 STRDUP_REP(pfx->prefix_path, pkg_bin);
198 if (!pfx->prefix_path) return 0; 189 if (!pfx->prefix_path) return 0;
199 p = strrchr(pfx->prefix_path, DSEP_C); 190 p = strrchr(pfx->prefix_path, EINA_PATH_SEP_C);
200 if (p) *p = 0; 191 if (p) *p = 0;
201 STRDUP_REP(pfx->prefix_path_bin, pkg_bin); 192 STRDUP_REP(pfx->prefix_path_bin, pkg_bin);
202 STRDUP_REP(pfx->prefix_path_lib, pkg_lib); 193 STRDUP_REP(pfx->prefix_path_lib, pkg_lib);
@@ -309,12 +300,12 @@ _try_argv(Eina_Prefix *pfx, const char *argv0)
309 } 300 }
310 301
311 /* 2. relative path */ 302 /* 2. relative path */
312 if (strchr(argv0, DSEP_C)) 303 if (strchr(argv0, EINA_PATH_SEP_C))
313 { 304 {
314 if (getcwd(buf2, sizeof(buf2))) 305 if (getcwd(buf2, sizeof(buf2)))
315 { 306 {
316 char joined[PATH_MAX]; 307 char joined[PATH_MAX];
317 _path_join(joined, sizeof(joined), buf2, argv0); 308 eina_file_path_join(joined, sizeof(joined), buf2, argv0);
318 if (realpath(joined, buf)) 309 if (realpath(joined, buf))
319 { 310 {
320 if (access(buf, X_OK) == 0) 311 if (access(buf, X_OK) == 0)
@@ -357,7 +348,7 @@ _try_argv(Eina_Prefix *pfx, const char *argv0)
357 } 348 }
358 349
359 strncpy(buf2, cp, len); 350 strncpy(buf2, cp, len);
360 buf2[len] = DSEP_C; 351 buf2[len] = EINA_PATH_SEP_C;
361 strcpy(buf2 + len + 1, argv0); 352 strcpy(buf2 + len + 1, argv0);
362 if (realpath(buf2, buf)) 353 if (realpath(buf2, buf))
363 { 354 {
@@ -400,7 +391,7 @@ _get_env_var(char **var, const char *envprefix, const char *envsuffix, const cha
400 else if (prefix) 391 else if (prefix)
401 { 392 {
402 char buf[PATH_MAX]; 393 char buf[PATH_MAX];
403 _path_join(buf, sizeof(buf), prefix, dir); 394 eina_file_path_join(buf, sizeof(buf), prefix, dir);
404 INF("Have %s_PREFIX = %s, use %s = %s", envprefix, prefix, env, buf); 395 INF("Have %s_PREFIX = %s, use %s = %s", envprefix, prefix, env, buf);
405 STRDUP_REP(*var, buf); 396 STRDUP_REP(*var, buf);
406 return 1; 397 return 1;
@@ -505,10 +496,10 @@ eina_prefix_new(const char *argv0, void *symbol, const char *envprefix,
505 { 496 {
506 int len; 497 int len;
507 498
508 len = _path_join(buf, sizeof(buf), datadir, sharedir); 499 len = eina_file_path_join(buf, sizeof(buf), datadir, sharedir);
509 if (len > 0) 500 if (len > 0)
510 { 501 {
511 _path_sep_fix(buf + strlen(datadir) + strlen(DSEP_S)); 502 _path_sep_fix(buf + strlen(datadir) + strlen(EINA_PATH_SEP_S));
512 tmp = alloca(len + 1); 503 tmp = alloca(len + 1);
513 strcpy(tmp, buf); 504 strcpy(tmp, buf);
514 datadir = tmp; 505 datadir = tmp;
@@ -642,13 +633,13 @@ eina_prefix_new(const char *argv0, void *symbol, const char *envprefix,
642 * exe = /blah/whatever/lib/arch/libexe.so 633 * exe = /blah/whatever/lib/arch/libexe.so
643 */ 634 */
644 DBG("From exe %s figure out the rest", pfx->exe_path); 635 DBG("From exe %s figure out the rest", pfx->exe_path);
645 p = strrchr(pfx->exe_path, DSEP_C); 636 p = strrchr(pfx->exe_path, EINA_PATH_SEP_C);
646 if (p) 637 if (p)
647 { 638 {
648 p--; 639 p--;
649 while (p >= pfx->exe_path) 640 while (p >= pfx->exe_path)
650 { 641 {
651 if (*p == DSEP_C) 642 if (*p == EINA_PATH_SEP_C)
652 { 643 {
653 if (pfx->prefix_path) free(pfx->prefix_path); 644 if (pfx->prefix_path) free(pfx->prefix_path);
654 pfx->prefix_path = malloc(p - pfx->exe_path + 1); 645 pfx->prefix_path = malloc(p - pfx->exe_path + 1);
@@ -663,21 +654,21 @@ eina_prefix_new(const char *argv0, void *symbol, const char *envprefix,
663 DBG("Have prefix = %s", pfx->prefix_path); 654 DBG("Have prefix = %s", pfx->prefix_path);
664 655
665 /* bin */ 656 /* bin */
666 _path_join(buf, sizeof(buf), pfx->prefix_path, bindir); 657 eina_file_path_join(buf, sizeof(buf), pfx->prefix_path, bindir);
667 STRDUP_REP(pfx->prefix_path_bin, buf); 658 STRDUP_REP(pfx->prefix_path_bin, buf);
668 DBG("Have bin = %s", pfx->prefix_path_bin); 659 DBG("Have bin = %s", pfx->prefix_path_bin);
669 if ((!from_bin) && (stat(buf, &st) == 0)) 660 if ((!from_bin) && (stat(buf, &st) == 0))
670 checks_passed++; 661 checks_passed++;
671 662
672 /* lib */ 663 /* lib */
673 _path_join(buf, sizeof(buf), pfx->prefix_path, libdir); 664 eina_file_path_join(buf, sizeof(buf), pfx->prefix_path, libdir);
674 STRDUP_REP(pfx->prefix_path_lib, buf); 665 STRDUP_REP(pfx->prefix_path_lib, buf);
675 DBG("Have lib = %s", pfx->prefix_path_lib); 666 DBG("Have lib = %s", pfx->prefix_path_lib);
676 if ((!from_lib) && (stat(buf, &st) == 0)) 667 if ((!from_lib) && (stat(buf, &st) == 0))
677 checks_passed++; 668 checks_passed++;
678 669
679 /* locale */ 670 /* locale */
680 _path_join(buf, sizeof(buf), pfx->prefix_path, localedir); 671 eina_file_path_join(buf, sizeof(buf), pfx->prefix_path, localedir);
681 STRDUP_REP(pfx->prefix_path_locale, buf); 672 STRDUP_REP(pfx->prefix_path_locale, buf);
682 DBG("Have locale = %s", pfx->prefix_path_locale); 673 DBG("Have locale = %s", pfx->prefix_path_locale);
683 if (stat(buf, &st) == 0) 674 if (stat(buf, &st) == 0)
@@ -708,14 +699,14 @@ eina_prefix_new(const char *argv0, void *symbol, const char *envprefix,
708 if (((!magic) && (checks_passed > 0)) || 699 if (((!magic) && (checks_passed > 0)) ||
709 ((magic) && (magic_found))) 700 ((magic) && (magic_found)))
710 { 701 {
711 _path_join(buf, sizeof(buf), pfx->prefix_path, datadir); 702 eina_file_path_join(buf, sizeof(buf), pfx->prefix_path, datadir);
712 STRDUP_REP(pfx->prefix_path_data, buf); 703 STRDUP_REP(pfx->prefix_path_data, buf);
713 } 704 }
714 else 705 else
715 { 706 {
716 for (;p > pfx->exe_path; p--) 707 for (;p > pfx->exe_path; p--)
717 { 708 {
718 if (*p == DSEP_C) 709 if (*p == EINA_PATH_SEP_C)
719 { 710 {
720 p--; 711 p--;
721 break; 712 break;