2011-04-24 00:49:43 -07:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2011 Carsten Haitzler
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-05-16 10:39:20 -07:00
|
|
|
#ifdef STDC_HEADERS
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <stddef.h>
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_STDLIB_H
|
|
|
|
# include <stdlib.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2013-01-10 12:25:26 -08:00
|
|
|
#include <unistd.h>
|
2011-04-24 00:35:30 -07:00
|
|
|
#include <limits.h>
|
2011-04-24 01:12:00 -07:00
|
|
|
|
2015-12-28 05:22:29 -08:00
|
|
|
#if defined HAVE_DLADDR && ! defined _WIN32
|
2011-04-24 00:35:30 -07:00
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2017-09-22 03:06:10 -07:00
|
|
|
#ifdef _WIN32
|
2019-05-08 05:39:36 -07:00
|
|
|
# include <direct.h> /* getcwd */
|
2019-05-16 10:48:59 -07:00
|
|
|
# include <evil_private.h> /* path_is_absolute realpath dladdr */
|
2011-04-24 00:35:30 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "eina_config.h"
|
|
|
|
#include "eina_private.h"
|
2013-01-03 07:10:34 -08:00
|
|
|
#include "eina_alloca.h"
|
2011-04-24 00:35:30 -07:00
|
|
|
#include "eina_log.h"
|
2013-01-09 07:21:40 -08:00
|
|
|
#include "eina_str.h"
|
2015-08-12 23:14:32 -07:00
|
|
|
#include "eina_file.h"
|
2013-01-09 07:21:40 -08:00
|
|
|
|
|
|
|
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
|
|
|
|
#include "eina_safety_checks.h"
|
2011-04-24 00:35:30 -07:00
|
|
|
#include "eina_prefix.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2011-04-24 00:57:16 -07:00
|
|
|
# define PSEP_C ';'
|
2011-04-24 00:35:30 -07:00
|
|
|
#else
|
2011-04-24 00:57:16 -07:00
|
|
|
# define PSEP_C ':'
|
2011-04-24 00:35:30 -07:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2011-04-24 00:49:43 -07:00
|
|
|
/*============================================================================*
|
|
|
|
* Local *
|
|
|
|
*============================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @cond LOCAL
|
|
|
|
*/
|
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
struct _Eina_Prefix
|
|
|
|
{
|
|
|
|
char *exe_path;
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
char *prefix_path;
|
|
|
|
char *prefix_path_bin;
|
|
|
|
char *prefix_path_data;
|
|
|
|
char *prefix_path_lib;
|
|
|
|
char *prefix_path_locale;
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
unsigned char fallback : 1;
|
|
|
|
unsigned char no_common_prefix : 1;
|
|
|
|
unsigned char env_used : 1;
|
|
|
|
};
|
|
|
|
|
2011-08-25 05:13:16 -07:00
|
|
|
#define STRDUP_REP(x, y) do { if (x) free(x); x = strdup(y); } while (0)
|
2011-04-24 00:35:30 -07:00
|
|
|
#define IF_FREE_NULL(p) do { if (p) { free(p); p = NULL; } } while (0)
|
2011-09-02 22:31:25 -07:00
|
|
|
|
|
|
|
#ifndef EINA_LOG_COLOR_DEFAULT
|
|
|
|
#define EINA_LOG_COLOR_DEFAULT EINA_COLOR_CYAN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ERR
|
|
|
|
#undef ERR
|
|
|
|
#endif
|
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(_eina_prefix_log_dom, __VA_ARGS__)
|
|
|
|
|
|
|
|
#ifdef WRN
|
|
|
|
#undef WRN
|
|
|
|
#endif
|
|
|
|
#define WRN(...) EINA_LOG_DOM_WARN(_eina_prefix_log_dom, __VA_ARGS__)
|
|
|
|
|
|
|
|
#ifdef INF
|
|
|
|
#undef INF
|
|
|
|
#endif
|
|
|
|
#define INF(...) EINA_LOG_DOM_INFO(_eina_prefix_log_dom, __VA_ARGS__)
|
|
|
|
|
|
|
|
#ifdef DBG
|
|
|
|
#undef DBG
|
|
|
|
#endif
|
|
|
|
#define DBG(...) EINA_LOG_DOM_DBG(_eina_prefix_log_dom, __VA_ARGS__)
|
|
|
|
|
|
|
|
static int _eina_prefix_log_dom = -1;
|
2011-04-24 00:35:30 -07:00
|
|
|
|
2013-01-09 07:21:40 -08:00
|
|
|
static int
|
|
|
|
_path_join_multiple(char *buf, int bufsize, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int used = 0;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(buf, -1);
|
|
|
|
EINA_SAFETY_ON_TRUE_RETURN_VAL(bufsize < 1, -1);
|
|
|
|
|
|
|
|
va_start(ap, bufsize);
|
|
|
|
while (used < bufsize - 1)
|
|
|
|
{
|
|
|
|
const char *comp = va_arg(ap, const char *);
|
|
|
|
int complen, seplen;
|
|
|
|
if (!comp) break;
|
|
|
|
|
|
|
|
|
|
|
|
seplen = (used == 0) ? 0 : 1;
|
|
|
|
complen = strlen(comp);
|
|
|
|
if (seplen + complen >= bufsize -1)
|
|
|
|
{
|
|
|
|
va_end(ap);
|
|
|
|
buf[0] = '\0';
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (used > 0)
|
2015-08-12 23:14:32 -07:00
|
|
|
buf[used] = EINA_PATH_SEP_C;
|
2013-01-09 07:21:40 -08:00
|
|
|
|
|
|
|
memcpy(buf + used + seplen, comp, complen);
|
|
|
|
used += complen + seplen;
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
buf[used] = '\0';
|
|
|
|
return used;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_path_sep_fix(char *buf)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
for (; *buf != '\0'; buf++)
|
|
|
|
{
|
|
|
|
if (*buf == '/')
|
2015-08-12 23:14:32 -07:00
|
|
|
*buf = EINA_PATH_SEP_C;
|
2013-01-09 07:21:40 -08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
(void)buf;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_path_absolute_check(const char *path)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return evil_path_is_absolute(path);
|
|
|
|
#else
|
2015-08-12 23:14:32 -07:00
|
|
|
return (path[0] == EINA_PATH_SEP_C);
|
2013-01-09 07:21:40 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
static int
|
|
|
|
_fallback(Eina_Prefix *pfx, const char *pkg_bin, const char *pkg_lib,
|
|
|
|
const char *pkg_data, const char *pkg_locale, const char *envprefix)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
STRDUP_REP(pfx->prefix_path, pkg_bin);
|
|
|
|
if (!pfx->prefix_path) return 0;
|
2015-08-12 23:14:32 -07:00
|
|
|
p = strrchr(pfx->prefix_path, EINA_PATH_SEP_C);
|
2011-04-24 00:35:30 -07:00
|
|
|
if (p) *p = 0;
|
|
|
|
STRDUP_REP(pfx->prefix_path_bin, pkg_bin);
|
|
|
|
STRDUP_REP(pfx->prefix_path_lib, pkg_lib);
|
|
|
|
STRDUP_REP(pfx->prefix_path_data, pkg_data);
|
|
|
|
STRDUP_REP(pfx->prefix_path_locale, pkg_locale);
|
2011-12-08 05:28:32 -08:00
|
|
|
WRN("Could not determine its installed prefix for '%s'\n"
|
|
|
|
" so am falling back on the compiled in default:\n"
|
|
|
|
" %s\n"
|
|
|
|
" implied by the following:\n"
|
|
|
|
" bindir = %s\n"
|
|
|
|
" libdir = %s\n"
|
|
|
|
" datadir = %s\n"
|
|
|
|
" localedir = %s\n"
|
|
|
|
" Try setting the following environment variables:\n"
|
|
|
|
" %s_PREFIX - points to the base prefix of install\n"
|
|
|
|
" or the next 4 variables\n"
|
|
|
|
" %s_BIN_DIR - provide a specific binary directory\n"
|
|
|
|
" %s_LIB_DIR - provide a specific library directory\n"
|
|
|
|
" %s_DATA_DIR - provide a specific data directory\n"
|
|
|
|
" %s_LOCALE_DIR - provide a specific locale directory",
|
|
|
|
envprefix,
|
|
|
|
pfx->prefix_path, pkg_bin, pkg_lib, pkg_data, pkg_locale,
|
|
|
|
envprefix, envprefix, envprefix, envprefix, envprefix);
|
2011-04-24 00:35:30 -07:00
|
|
|
pfx->fallback = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_try_proc(Eina_Prefix *pfx, void *symbol)
|
|
|
|
{
|
2013-01-09 07:57:28 -08:00
|
|
|
#ifndef _WIN32
|
2011-04-24 00:35:30 -07:00
|
|
|
FILE *f;
|
|
|
|
char buf[4096];
|
|
|
|
|
|
|
|
f = fopen("/proc/self/maps", "rb");
|
2013-01-09 07:21:40 -08:00
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
WRN("Couldn't read /proc/self/maps to lookup symbol=%p", symbol);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DBG("Check /proc/self/maps for symbol=%p", symbol);
|
2011-04-24 00:35:30 -07:00
|
|
|
while (fgets(buf, sizeof(buf), f))
|
|
|
|
{
|
2013-01-09 08:00:39 -08:00
|
|
|
int len;
|
|
|
|
char *p, mode[5] = "";
|
|
|
|
unsigned long ptr1 = 0, ptr2 = 0;
|
|
|
|
|
|
|
|
len = strlen(buf);
|
|
|
|
if (buf[len - 1] == '\n')
|
|
|
|
{
|
|
|
|
buf[len - 1] = 0;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
if (sscanf(buf, "%lx-%lx %4s", &ptr1, &ptr2, mode) == 3)
|
|
|
|
{
|
|
|
|
if (!strcmp(mode, "r-xp"))
|
|
|
|
{
|
|
|
|
if (((void *)ptr1 <= symbol) && (symbol < (void *)ptr2))
|
|
|
|
{
|
|
|
|
p = strchr(buf, '/');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
if (len > 10)
|
|
|
|
{
|
|
|
|
if (!strcmp(buf + len - 10, " (deleted)"))
|
|
|
|
buf[len - 10] = 0;
|
|
|
|
}
|
2011-04-24 00:35:30 -07:00
|
|
|
STRDUP_REP(pfx->exe_path, p);
|
2013-01-09 07:21:40 -08:00
|
|
|
INF("Found %p in /proc/self/maps: %s (%s)", symbol, pfx->exe_path, buf);
|
2013-01-09 08:00:39 -08:00
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
2013-01-09 07:21:40 -08:00
|
|
|
{
|
|
|
|
DBG("Found %p in /proc/self/maps but not a file (%s)", symbol, buf);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-09 08:00:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
|
|
|
fclose(f);
|
2013-01-09 07:21:40 -08:00
|
|
|
WRN("Couldn't find symbol %p in a file in /proc/self/maps", symbol);
|
2011-04-24 00:35:30 -07:00
|
|
|
return 0;
|
2013-01-09 07:57:28 -08:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
(void)pfx;
|
|
|
|
(void)symbol;
|
2011-04-24 00:35:30 -07:00
|
|
|
#endif
|
2013-01-09 07:57:28 -08:00
|
|
|
}
|
2011-04-24 00:35:30 -07:00
|
|
|
|
|
|
|
static int
|
|
|
|
_try_argv(Eina_Prefix *pfx, const char *argv0)
|
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
char *path, *p, *cp;
|
2011-04-24 00:35:30 -07:00
|
|
|
int len, lenexe;
|
2013-01-09 07:21:40 -08:00
|
|
|
char buf[PATH_MAX], buf2[PATH_MAX];
|
2011-04-24 00:35:30 -07:00
|
|
|
|
|
|
|
/* 1. is argv0 abs path? */
|
2013-01-09 07:21:40 -08:00
|
|
|
if (_path_absolute_check(argv0))
|
2011-04-24 00:35:30 -07:00
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
if (access(argv0, X_OK) == 0)
|
2011-06-07 19:59:52 -07:00
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
INF("Executable argv0 is full path = %s", argv0);
|
|
|
|
STRDUP_REP(pfx->exe_path, argv0);
|
2011-06-07 19:59:52 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2013-01-09 07:21:40 -08:00
|
|
|
WRN("Non executable argv0: %s", argv0);
|
|
|
|
return 0;
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
2013-01-09 07:21:40 -08:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
/* 2. relative path */
|
2015-08-12 23:14:32 -07:00
|
|
|
if (strchr(argv0, EINA_PATH_SEP_C))
|
2011-04-24 00:35:30 -07:00
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
if (getcwd(buf2, sizeof(buf2)))
|
|
|
|
{
|
2020-06-06 17:33:43 -07:00
|
|
|
size_t len = strlen(buf2) + 1 + strlen(argv0) + 1;
|
|
|
|
char *joined = alloca(len);
|
|
|
|
eina_file_path_join(joined, len, buf2, argv0);
|
2013-01-09 07:21:40 -08:00
|
|
|
if (realpath(joined, buf))
|
|
|
|
{
|
|
|
|
if (access(buf, X_OK) == 0)
|
2011-06-07 19:59:52 -07:00
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
INF("Executable relative argv0=%s, cwd=%s, realpath=%s",
|
|
|
|
argv0, buf2, buf);
|
|
|
|
STRDUP_REP(pfx->exe_path, buf);
|
2011-06-07 19:59:52 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2013-01-09 07:21:40 -08:00
|
|
|
WRN("Non executable relative argv0=%s, cwd=%s, realpath=%s",
|
|
|
|
argv0, buf2, buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WRN("No realpath for argv0=%s, cwd=%s", argv0, buf2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WRN("Couldn't get current directory to lookup argv0=%s", argv0);
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
2013-01-09 07:21:40 -08:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
/* 3. argv0 no path - look in PATH */
|
2014-01-08 05:06:41 -08:00
|
|
|
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
|
|
|
if (getuid() != geteuid()) return 0;
|
|
|
|
#endif
|
2011-04-24 00:35:30 -07:00
|
|
|
path = getenv("PATH");
|
2013-01-09 07:21:40 -08:00
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
DBG("No env PATH to lookup argv0=%s", argv0);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-04-24 00:35:30 -07:00
|
|
|
p = path;
|
|
|
|
cp = p;
|
|
|
|
lenexe = strlen(argv0);
|
2011-04-24 00:57:16 -07:00
|
|
|
while ((p = strchr(cp, PSEP_C)))
|
2011-04-24 00:35:30 -07:00
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
len = p - cp;
|
|
|
|
if ((len == 0) || (len + lenexe + 2 >= (int)sizeof(buf2)))
|
|
|
|
{
|
|
|
|
cp = p + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(buf2, cp, len);
|
2015-08-12 23:14:32 -07:00
|
|
|
buf2[len] = EINA_PATH_SEP_C;
|
2013-01-09 07:21:40 -08:00
|
|
|
strcpy(buf2 + len + 1, argv0);
|
|
|
|
if (realpath(buf2, buf))
|
|
|
|
{
|
|
|
|
if (access(buf, X_OK) == 0)
|
|
|
|
{
|
|
|
|
STRDUP_REP(pfx->exe_path, buf);
|
|
|
|
INF("Path %s is executable", pfx->exe_path);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DBG("Path not executable %s", buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DBG("No realpath for argv0=%s in %.*s", argv0, len, cp);
|
2011-04-24 00:35:30 -07:00
|
|
|
cp = p + 1;
|
|
|
|
}
|
|
|
|
/* 4. big problems. arg[0] != executable - weird execution */
|
2013-01-09 07:21:40 -08:00
|
|
|
WRN("Couldn't find argv0=%s in current directory or env PATH=%s",
|
|
|
|
argv0, path);
|
2011-04-24 00:35:30 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-01-09 07:21:40 -08:00
|
|
|
_get_env_var(char **var, const char *envprefix, const char *envsuffix, const char *prefix, const char *dir)
|
2011-04-24 00:35:30 -07:00
|
|
|
{
|
2020-06-06 17:33:43 -07:00
|
|
|
char env[64];
|
2013-01-09 07:21:40 -08:00
|
|
|
const char *s;
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2014-01-08 05:06:41 -08:00
|
|
|
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
|
|
|
if (getuid() != geteuid()) return 0;
|
|
|
|
#endif
|
2013-01-09 07:21:40 -08:00
|
|
|
snprintf(env, sizeof(env), "%s_%s_DIR", envprefix, envsuffix);
|
|
|
|
s = getenv(env);
|
2011-04-24 00:35:30 -07:00
|
|
|
if (s)
|
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
INF("Have prefix env %s = %s", env, s);
|
2011-04-24 00:35:30 -07:00
|
|
|
STRDUP_REP(*var, s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (prefix)
|
|
|
|
{
|
2020-06-06 17:33:43 -07:00
|
|
|
size_t len = strlen(prefix) + 1 + strlen(dir) + 1;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
buf = alloca(len);
|
|
|
|
eina_file_path_join(buf, len, prefix, dir);
|
2013-01-09 07:21:40 -08:00
|
|
|
INF("Have %s_PREFIX = %s, use %s = %s", envprefix, prefix, env, buf);
|
2011-04-24 00:35:30 -07:00
|
|
|
STRDUP_REP(*var, buf);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-09 07:21:40 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG("No env %s_PREFIX or %s for dir '%s'", envprefix, env, dir);
|
2017-10-04 20:57:08 -07:00
|
|
|
STRDUP_REP(*var, "");
|
2013-01-09 07:21:40 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_get_env_vars(Eina_Prefix *pfx,
|
|
|
|
const char *envprefix,
|
|
|
|
const char *bindir,
|
|
|
|
const char *libdir,
|
|
|
|
const char *datadir,
|
|
|
|
const char *localedir)
|
|
|
|
{
|
2020-06-06 17:33:43 -07:00
|
|
|
char env[32];
|
2013-01-09 07:21:40 -08:00
|
|
|
const char *prefix;
|
2011-04-24 00:35:30 -07:00
|
|
|
int ret = 0;
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2014-01-08 05:06:41 -08:00
|
|
|
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
|
|
|
if (getuid() == geteuid())
|
|
|
|
#endif
|
2014-01-08 02:46:23 -08:00
|
|
|
{
|
|
|
|
snprintf(env, sizeof(env), "%s_PREFIX", envprefix);
|
|
|
|
if ((prefix = getenv(env))) STRDUP_REP(pfx->prefix_path, prefix);
|
2013-01-09 07:21:40 -08:00
|
|
|
|
2014-01-08 02:46:23 -08:00
|
|
|
ret += _get_env_var(&pfx->prefix_path_bin, envprefix, "BIN", prefix, bindir);
|
|
|
|
ret += _get_env_var(&pfx->prefix_path_lib, envprefix, "LIB", prefix, libdir);
|
|
|
|
ret += _get_env_var(&pfx->prefix_path_data, envprefix, "DATA", prefix, datadir);
|
|
|
|
ret += _get_env_var(&pfx->prefix_path_locale, envprefix, "LOCALE", prefix, localedir);
|
|
|
|
}
|
2011-04-24 00:35:30 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-09 07:46:05 -08:00
|
|
|
static int
|
|
|
|
_common_prefix_find(const char *bin, const char *lib, const char *data, const char *locale)
|
|
|
|
{
|
|
|
|
const char *b = bin;
|
|
|
|
const char *i = lib;
|
|
|
|
const char *d = data;
|
|
|
|
const char *o = locale;
|
|
|
|
|
|
|
|
for (; (*b) && (*i) && (*d) && (*o); b++, i++, d++, o++)
|
|
|
|
{
|
|
|
|
if (*b != *i) break;
|
|
|
|
if (*b != *d) break;
|
|
|
|
if (*b != *o) break;
|
|
|
|
}
|
|
|
|
return b - bin;
|
|
|
|
}
|
|
|
|
|
2011-04-24 00:49:43 -07:00
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* Global *
|
|
|
|
*============================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* API *
|
|
|
|
*============================================================================*/
|
|
|
|
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Prefix *
|
2011-04-24 00:35:30 -07:00
|
|
|
eina_prefix_new(const char *argv0, void *symbol, const char *envprefix,
|
|
|
|
const char *sharedir, const char *magicsharefile,
|
|
|
|
const char *pkg_bin, const char *pkg_lib,
|
|
|
|
const char *pkg_data, const char *pkg_locale)
|
|
|
|
{
|
|
|
|
Eina_Prefix *pfx;
|
2011-08-25 05:13:16 -07:00
|
|
|
char *p, buf[4096], *tmp, *magic = NULL;
|
2011-04-24 00:35:30 -07:00
|
|
|
struct stat st;
|
2013-01-09 07:46:05 -08:00
|
|
|
int prefixlen;
|
2011-04-24 00:35:30 -07:00
|
|
|
const char *bindir = "bin";
|
|
|
|
const char *libdir = "lib";
|
|
|
|
const char *datadir = "share";
|
|
|
|
const char *localedir = "share";
|
2013-01-08 15:57:14 -08:00
|
|
|
Eina_Bool from_lib = EINA_FALSE, from_bin = EINA_FALSE;
|
2011-04-24 00:35:30 -07:00
|
|
|
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("EINA PREFIX: argv0=%s, symbol=%p, magicsharefile=%s, envprefix=%s",
|
|
|
|
argv0, symbol, magicsharefile, envprefix);
|
2013-01-09 07:21:40 -08:00
|
|
|
DBG("EINA PREFIX: share=%s, bin=%s, lib=%s, data=%s, locale=%s",
|
|
|
|
sharedir, pkg_bin, pkg_lib, pkg_data, pkg_locale);
|
2013-01-09 07:38:42 -08:00
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pkg_bin, NULL);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pkg_lib, NULL);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pkg_data, NULL);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pkg_locale, NULL);
|
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
pfx = calloc(1, sizeof(Eina_Prefix));
|
|
|
|
if (!pfx) return NULL;
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
/* if provided with a share dir use datadir/sharedir as the share dir */
|
|
|
|
if (sharedir)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2015-08-12 23:14:32 -07:00
|
|
|
len = eina_file_path_join(buf, sizeof(buf), datadir, sharedir);
|
2011-04-24 00:35:30 -07:00
|
|
|
if (len > 0)
|
|
|
|
{
|
2015-08-12 23:14:32 -07:00
|
|
|
_path_sep_fix(buf + strlen(datadir) + strlen(EINA_PATH_SEP_S));
|
2011-04-24 00:35:30 -07:00
|
|
|
tmp = alloca(len + 1);
|
|
|
|
strcpy(tmp, buf);
|
|
|
|
datadir = tmp;
|
|
|
|
}
|
|
|
|
}
|
2019-05-29 06:16:35 -07:00
|
|
|
if (magicsharefile && (!getenv("EFL_RUN_IN_TREE")))
|
2011-04-24 00:35:30 -07:00
|
|
|
{
|
2013-02-18 05:18:04 -08:00
|
|
|
magic = alloca(strlen(magicsharefile) + 1);
|
2011-04-24 00:35:30 -07:00
|
|
|
strcpy(magic, magicsharefile);
|
2013-01-09 07:21:40 -08:00
|
|
|
_path_sep_fix(magic);
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* look at compile-time package bin/lib/datadir etc. and figure out the
|
|
|
|
* bin, lib and data dirs from these, if possible. i.e.
|
|
|
|
* bin = /usr/local/bin
|
|
|
|
* lib = /usr/local/lib
|
|
|
|
* data = /usr/local/share/enlightenment
|
|
|
|
* thus they all have a common prefix string of /usr/local/ and
|
|
|
|
* bindir = bin
|
|
|
|
* libdir = lib
|
|
|
|
* datadir = share/enlightenment
|
|
|
|
* this addresses things like libdir is lib64 or lib32 or other such
|
|
|
|
* junk distributions like to do so then:
|
|
|
|
* bin = /usr/local/bin
|
|
|
|
* lib = /usr/local/lib64
|
|
|
|
* data = /usr/local/share/enlightenment
|
|
|
|
* then
|
|
|
|
* bindir = bin
|
|
|
|
* libdir = lib64
|
|
|
|
* datadir = share/enlightennment
|
2011-08-22 16:40:05 -07:00
|
|
|
* in theory this should also work with debians new multiarch style like
|
|
|
|
* bindir = bin
|
|
|
|
* libdir = lib/i386-linux-gnu
|
|
|
|
* or
|
|
|
|
* libdir = lib/x86_64-linux-gnu
|
2011-04-24 00:35:30 -07:00
|
|
|
* all with a common prefix that can be relocated
|
|
|
|
*/
|
2013-01-09 07:46:05 -08:00
|
|
|
prefixlen = _common_prefix_find(pkg_bin, pkg_lib, pkg_data, pkg_locale);
|
|
|
|
if (prefixlen > 0)
|
2011-04-24 00:35:30 -07:00
|
|
|
{
|
2013-01-09 07:46:05 -08:00
|
|
|
bindir = pkg_bin + prefixlen;
|
|
|
|
libdir = pkg_lib + prefixlen;
|
|
|
|
datadir = pkg_data + prefixlen;
|
|
|
|
localedir = pkg_locale + prefixlen;
|
2013-01-09 07:21:40 -08:00
|
|
|
DBG("Prefix common=%.*s, bin=%s, lib=%s, data=%s, locale=%s",
|
2013-01-09 07:46:05 -08:00
|
|
|
prefixlen, pkg_bin, bindir, libdir, datadir, localedir);
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
|
|
|
/* 3. some galoot thought it awesome not to give us a common prefix at compile time
|
|
|
|
* so fall back to the compile time directories. we are no longer relocatable */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
STRDUP_REP(pfx->prefix_path_bin, pkg_bin);
|
|
|
|
STRDUP_REP(pfx->prefix_path_lib, pkg_lib);
|
|
|
|
STRDUP_REP(pfx->prefix_path_data, pkg_data);
|
|
|
|
STRDUP_REP(pfx->prefix_path_locale, pkg_locale);
|
|
|
|
pfx->no_common_prefix = 1;
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("Can't work out a common prefix - compiled in fallback");
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
/* if user provides env vars - then use that or also more specific sub
|
|
|
|
* dirs for bin, lib, data and locale */
|
|
|
|
if ((envprefix) &&
|
|
|
|
(_get_env_vars(pfx, envprefix, bindir, libdir, datadir, localedir) > 0))
|
|
|
|
{
|
|
|
|
pfx->env_used = 1;
|
|
|
|
return pfx;
|
|
|
|
}
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
if (symbol)
|
|
|
|
{
|
2013-01-09 07:57:28 -08:00
|
|
|
#ifdef HAVE_DLADDR
|
2011-04-24 00:35:30 -07:00
|
|
|
Dl_info info_dl;
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
if (dladdr(symbol, &info_dl))
|
|
|
|
{
|
2011-04-24 02:53:00 -07:00
|
|
|
if (info_dl.dli_fname)
|
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
if (_path_absolute_check(info_dl.dli_fname))
|
2011-06-07 19:59:52 -07:00
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
INF("dladdr for symbol=%p: %s", symbol, info_dl.dli_fname);
|
2018-08-24 03:32:10 -07:00
|
|
|
char *rlink = realpath(info_dl.dli_fname, NULL);
|
|
|
|
if (rlink)
|
|
|
|
{
|
|
|
|
IF_FREE_NULL(pfx->exe_path);
|
|
|
|
pfx->exe_path = rlink;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
STRDUP_REP(pfx->exe_path, info_dl.dli_fname);
|
|
|
|
}
|
2013-01-08 15:57:14 -08:00
|
|
|
from_lib = EINA_TRUE;
|
2011-06-07 19:59:52 -07:00
|
|
|
}
|
2013-01-09 07:21:40 -08:00
|
|
|
else
|
|
|
|
WRN("dladdr for symbol=%p: %s is relative", symbol, info_dl.dli_fname);
|
2011-04-24 02:53:00 -07:00
|
|
|
}
|
2013-01-09 07:21:40 -08:00
|
|
|
else
|
|
|
|
WRN("no dladdr filename for symbol=%p", symbol);
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
2013-01-09 07:21:40 -08:00
|
|
|
else
|
|
|
|
WRN("no dladdr for symbol=%p", symbol);
|
2011-04-24 00:49:43 -07:00
|
|
|
#endif
|
2013-01-09 07:57:28 -08:00
|
|
|
|
|
|
|
if (!pfx->exe_path)
|
|
|
|
_try_proc(pfx, symbol);
|
|
|
|
/* no from_lib/from_bin as we're not sure it came from lib or bin! */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no env var or symbol - examine process and possible argv0 */
|
|
|
|
if ((argv0) && (!pfx->exe_path))
|
2011-04-24 00:35:30 -07:00
|
|
|
{
|
2013-01-09 07:57:28 -08:00
|
|
|
if (!_try_argv(pfx, argv0))
|
2011-04-24 00:35:30 -07:00
|
|
|
{
|
2013-01-09 07:57:28 -08:00
|
|
|
WRN("Fallback - couldn't resolve based on argv0=%s", argv0);
|
|
|
|
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale,
|
|
|
|
envprefix);
|
|
|
|
return pfx;
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
2013-01-09 07:57:28 -08:00
|
|
|
|
|
|
|
from_bin = EINA_TRUE;
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
2013-01-09 07:57:28 -08:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
if (!pfx->exe_path)
|
|
|
|
{
|
2013-01-09 07:21:40 -08:00
|
|
|
WRN("Fallback - no variables, symbol or argv0 could be used.");
|
2011-04-24 00:35:30 -07:00
|
|
|
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale, envprefix);
|
|
|
|
return pfx;
|
|
|
|
}
|
|
|
|
/* _exe_path is now a full absolute path TO this exe - figure out rest */
|
|
|
|
/* if
|
|
|
|
* exe = /blah/whatever/bin/exe
|
|
|
|
* or
|
|
|
|
* exe = /blah/whatever/lib/libexe.so
|
|
|
|
* then
|
|
|
|
* prefix = /blah/whatever
|
|
|
|
* bin_dir = /blah/whatever/bin
|
|
|
|
* data_dir = /blah/whatever/share/enlightenment
|
|
|
|
* lib_dir = /blah/whatever/lib
|
2013-01-09 08:00:39 -08:00
|
|
|
*
|
2012-07-31 23:28:37 -07:00
|
|
|
* new case - debian multiarch goop.
|
|
|
|
* exe = /blah/whatever/lib/arch/libexe.so
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("From exe %s figure out the rest", pfx->exe_path);
|
2015-08-12 23:14:32 -07:00
|
|
|
p = strrchr(pfx->exe_path, EINA_PATH_SEP_C);
|
2011-04-24 00:35:30 -07:00
|
|
|
if (p)
|
|
|
|
{
|
2013-01-09 08:00:39 -08:00
|
|
|
p--;
|
|
|
|
while (p >= pfx->exe_path)
|
|
|
|
{
|
2015-08-12 23:14:32 -07:00
|
|
|
if (*p == EINA_PATH_SEP_C)
|
2013-01-09 08:00:39 -08:00
|
|
|
{
|
2012-08-03 21:14:22 -07:00
|
|
|
if (pfx->prefix_path) free(pfx->prefix_path);
|
2013-01-09 08:00:39 -08:00
|
|
|
pfx->prefix_path = malloc(p - pfx->exe_path + 1);
|
|
|
|
if (pfx->prefix_path)
|
|
|
|
{
|
2013-01-08 15:57:14 -08:00
|
|
|
Eina_Bool magic_found = EINA_FALSE;
|
|
|
|
int checks_passed = 0;
|
|
|
|
|
2013-01-09 08:00:39 -08:00
|
|
|
strncpy(pfx->prefix_path, pfx->exe_path,
|
2011-04-24 00:35:30 -07:00
|
|
|
p - pfx->exe_path);
|
2013-01-09 08:00:39 -08:00
|
|
|
pfx->prefix_path[p - pfx->exe_path] = 0;
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("Have prefix = %s", pfx->prefix_path);
|
2011-04-24 00:35:30 -07:00
|
|
|
|
2013-01-09 08:00:39 -08:00
|
|
|
/* bin */
|
2015-08-12 23:14:32 -07:00
|
|
|
eina_file_path_join(buf, sizeof(buf), pfx->prefix_path, bindir);
|
2011-04-24 00:35:30 -07:00
|
|
|
STRDUP_REP(pfx->prefix_path_bin, buf);
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("Have bin = %s", pfx->prefix_path_bin);
|
2013-01-08 15:57:14 -08:00
|
|
|
if ((!from_bin) && (stat(buf, &st) == 0))
|
|
|
|
checks_passed++;
|
|
|
|
|
2013-01-09 08:00:39 -08:00
|
|
|
/* lib */
|
2015-08-12 23:14:32 -07:00
|
|
|
eina_file_path_join(buf, sizeof(buf), pfx->prefix_path, libdir);
|
2011-04-24 00:35:30 -07:00
|
|
|
STRDUP_REP(pfx->prefix_path_lib, buf);
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("Have lib = %s", pfx->prefix_path_lib);
|
2013-01-08 15:57:14 -08:00
|
|
|
if ((!from_lib) && (stat(buf, &st) == 0))
|
|
|
|
checks_passed++;
|
|
|
|
|
2013-01-09 08:00:39 -08:00
|
|
|
/* locale */
|
2015-08-12 23:14:32 -07:00
|
|
|
eina_file_path_join(buf, sizeof(buf), pfx->prefix_path, localedir);
|
2011-04-24 00:35:30 -07:00
|
|
|
STRDUP_REP(pfx->prefix_path_locale, buf);
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("Have locale = %s", pfx->prefix_path_locale);
|
2013-01-08 15:57:14 -08:00
|
|
|
if (stat(buf, &st) == 0)
|
|
|
|
checks_passed++;
|
|
|
|
|
2013-01-09 08:00:39 -08:00
|
|
|
/* check if magic file is there - then our guess is right */
|
2013-01-08 15:57:14 -08:00
|
|
|
if (!magic)
|
|
|
|
DBG("No magic file");
|
|
|
|
else
|
2011-06-07 19:59:52 -07:00
|
|
|
{
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("Magic = %s", magic);
|
2013-01-09 07:21:40 -08:00
|
|
|
_path_join_multiple(buf, sizeof(buf),
|
|
|
|
pfx->prefix_path,
|
|
|
|
datadir,
|
|
|
|
magic, NULL);
|
2011-09-02 22:31:25 -07:00
|
|
|
DBG("Check in %s", buf);
|
2013-01-08 15:57:14 -08:00
|
|
|
|
|
|
|
if (stat(buf, &st) == 0)
|
|
|
|
{
|
|
|
|
checks_passed++;
|
|
|
|
magic_found = EINA_TRUE;
|
|
|
|
DBG("Magic path %s stat passed", buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WRN("Missing magic path %s", buf);
|
2011-06-07 19:59:52 -07:00
|
|
|
}
|
2013-01-08 15:57:14 -08:00
|
|
|
|
2013-01-09 08:00:39 -08:00
|
|
|
if (((!magic) && (checks_passed > 0)) ||
|
2013-01-08 15:57:14 -08:00
|
|
|
((magic) && (magic_found)))
|
2013-01-09 08:00:39 -08:00
|
|
|
{
|
2015-08-12 23:14:32 -07:00
|
|
|
eina_file_path_join(buf, sizeof(buf), pfx->prefix_path, datadir);
|
2011-04-24 00:35:30 -07:00
|
|
|
STRDUP_REP(pfx->prefix_path_data, buf);
|
2013-01-09 08:00:39 -08:00
|
|
|
}
|
|
|
|
else
|
2011-04-24 02:53:00 -07:00
|
|
|
{
|
2013-01-08 15:57:14 -08:00
|
|
|
for (;p > pfx->exe_path; p--)
|
2012-07-31 23:28:37 -07:00
|
|
|
{
|
2015-08-12 23:14:32 -07:00
|
|
|
if (*p == EINA_PATH_SEP_C)
|
2012-07-31 23:28:37 -07:00
|
|
|
{
|
2013-01-08 15:57:14 -08:00
|
|
|
p--;
|
|
|
|
break;
|
2012-07-31 23:28:37 -07:00
|
|
|
}
|
|
|
|
}
|
2013-01-08 15:57:14 -08:00
|
|
|
if (p > pfx->exe_path)
|
|
|
|
{
|
|
|
|
int newlen = p - pfx->exe_path;
|
|
|
|
DBG("Go back one directory (%.*s)", newlen, pfx->exe_path);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
WRN("No Prefix path (exhausted search depth)");
|
2011-04-24 02:53:00 -07:00
|
|
|
_fallback(pfx, pkg_bin, pkg_lib, pkg_data,
|
|
|
|
pkg_locale, envprefix);
|
|
|
|
}
|
2013-01-09 08:00:39 -08:00
|
|
|
}
|
|
|
|
else
|
2011-04-24 02:53:00 -07:00
|
|
|
{
|
2011-09-02 22:31:25 -07:00
|
|
|
WRN("No Prefix path (alloc fail)");
|
2011-04-24 02:53:00 -07:00
|
|
|
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale,
|
|
|
|
envprefix);
|
|
|
|
}
|
2011-04-24 00:35:30 -07:00
|
|
|
return pfx;
|
2013-01-09 08:00:39 -08:00
|
|
|
}
|
|
|
|
p--;
|
|
|
|
}
|
2011-04-24 00:35:30 -07:00
|
|
|
}
|
2011-09-02 22:31:25 -07:00
|
|
|
WRN("Final fallback");
|
2011-04-24 00:35:30 -07:00
|
|
|
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale, envprefix);
|
|
|
|
return pfx;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void
|
2011-04-24 00:35:30 -07:00
|
|
|
eina_prefix_free(Eina_Prefix *pfx)
|
|
|
|
{
|
2013-01-09 07:38:42 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(pfx);
|
2011-04-24 00:49:43 -07:00
|
|
|
|
2011-04-24 00:35:30 -07:00
|
|
|
IF_FREE_NULL(pfx->exe_path);
|
|
|
|
IF_FREE_NULL(pfx->prefix_path);
|
|
|
|
IF_FREE_NULL(pfx->prefix_path_bin);
|
|
|
|
IF_FREE_NULL(pfx->prefix_path_data);
|
|
|
|
IF_FREE_NULL(pfx->prefix_path_lib);
|
|
|
|
IF_FREE_NULL(pfx->prefix_path_locale);
|
|
|
|
free(pfx);
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API const char *
|
2011-04-24 00:35:30 -07:00
|
|
|
eina_prefix_get(Eina_Prefix *pfx)
|
|
|
|
{
|
2013-01-09 07:38:42 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pfx, "");
|
2011-04-24 00:35:30 -07:00
|
|
|
return pfx->prefix_path;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API const char *
|
2011-04-24 00:35:30 -07:00
|
|
|
eina_prefix_bin_get(Eina_Prefix *pfx)
|
|
|
|
{
|
2013-01-09 07:38:42 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pfx, "");
|
2011-04-24 00:35:30 -07:00
|
|
|
return pfx->prefix_path_bin;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API const char *
|
2011-04-24 00:35:30 -07:00
|
|
|
eina_prefix_lib_get(Eina_Prefix *pfx)
|
|
|
|
{
|
2013-01-09 07:38:42 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pfx, "");
|
2011-04-24 00:35:30 -07:00
|
|
|
return pfx->prefix_path_lib;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API const char *
|
2011-04-24 00:35:30 -07:00
|
|
|
eina_prefix_data_get(Eina_Prefix *pfx)
|
|
|
|
{
|
2013-01-09 07:38:42 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pfx, "");
|
2011-04-24 00:35:30 -07:00
|
|
|
return pfx->prefix_path_data;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API const char *
|
2011-04-24 00:35:30 -07:00
|
|
|
eina_prefix_locale_get(Eina_Prefix *pfx)
|
|
|
|
{
|
2013-01-09 07:38:42 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(pfx, "");
|
2011-04-24 00:35:30 -07:00
|
|
|
return pfx->prefix_path_locale;
|
|
|
|
}
|
2011-09-02 22:31:25 -07:00
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
eina_prefix_init(void)
|
|
|
|
{
|
|
|
|
_eina_prefix_log_dom = eina_log_domain_register("eina_prefix",
|
|
|
|
EINA_LOG_COLOR_DEFAULT);
|
|
|
|
if (_eina_prefix_log_dom < 0)
|
|
|
|
{
|
|
|
|
EINA_LOG_ERR("Could not register log domain: eina_prefix");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
eina_prefix_shutdown(void)
|
|
|
|
{
|
|
|
|
eina_log_domain_unregister(_eina_prefix_log_dom);
|
|
|
|
_eina_prefix_log_dom = -1;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|