extractor_plugpath.c (libextractor-1.10) | : | extractor_plugpath.c (libextractor-1.11) | ||
---|---|---|---|---|
skipping to change at line 27 | skipping to change at line 27 | |||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |||
Boston, MA 02110-1301, USA. | Boston, MA 02110-1301, USA. | |||
*/ | */ | |||
/** | /** | |||
* @file main/extractor_plugpath.c | * @file main/extractor_plugpath.c | |||
* @brief determine path where plugins are installed | * @brief determine path where plugins are installed | |||
* @author Christian Grothoff | * @author Christian Grothoff | |||
*/ | */ | |||
#include "platform.h" | #include "platform.h" | |||
#include "plibc.h" | ||||
#include "extractor.h" | #include "extractor.h" | |||
#include <dirent.h> | #include <dirent.h> | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <signal.h> | #include <signal.h> | |||
#include <ltdl.h> | #include <ltdl.h> | |||
#include "extractor_plugpath.h" | #include "extractor_plugpath.h" | |||
#include "extractor_logging.h" | #include "extractor_logging.h" | |||
/** | /** | |||
skipping to change at line 104 | skipping to change at line 103 | |||
char *lnk; | char *lnk; | |||
char *ret; | char *ret; | |||
char *lestr; | char *lestr; | |||
ssize_t size; | ssize_t size; | |||
FILE *f; | FILE *f; | |||
snprintf (fn, | snprintf (fn, | |||
sizeof (fn), | sizeof (fn), | |||
"/proc/%u/maps", | "/proc/%u/maps", | |||
getpid ()); | getpid ()); | |||
if (NULL != (f = FOPEN (fn, "r"))) | if (NULL != (f = fopen (fn, "r"))) | |||
{ | { | |||
while (NULL != fgets (line, 1024, f)) | while (NULL != fgets (line, 1024, f)) | |||
{ | { | |||
if ( (1 == sscanf (line, | if ( (1 == sscanf (line, | |||
"%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%s", | "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%s", | |||
dir)) && | dir)) && | |||
(NULL != (lestr = strstr (dir, | (NULL != (lestr = strstr (dir, | |||
"libextractor")) ) ) | "libextractor")) ) ) | |||
{ | { | |||
lestr[0] = '\0'; | lestr[0] = '\0'; | |||
skipping to change at line 410 | skipping to change at line 409 | |||
*/ | */ | |||
static char * | static char * | |||
append_to_dir (const char *path, | append_to_dir (const char *path, | |||
const char *fname) | const char *fname) | |||
{ | { | |||
char *ret; | char *ret; | |||
size_t slen; | size_t slen; | |||
if (0 == (slen = strlen (path))) | if (0 == (slen = strlen (path))) | |||
return NULL; | return NULL; | |||
if (DIR_SEPARATOR == fname[0]) | if ('/' == fname[0]) | |||
fname++; | fname++; | |||
ret = malloc (slen + strlen (fname) + 2); | ret = malloc (slen + strlen (fname) + 2); | |||
if (NULL == ret) | if (NULL == ret) | |||
return NULL; | return NULL; | |||
#ifdef MINGW | #ifdef MINGW | |||
if ('\\' == path[slen - 1]) | if ('\\' == path[slen - 1]) | |||
sprintf (ret, | sprintf (ret, | |||
"%s%s", | "%s%s", | |||
path, | path, | |||
fname); | fname); | |||
skipping to change at line 466 | skipping to change at line 465 | |||
char *saveptr; | char *saveptr; | |||
prefix = NULL; | prefix = NULL; | |||
if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX"))) | if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX"))) | |||
{ | { | |||
if (NULL == (d = strdup (p))) | if (NULL == (d = strdup (p))) | |||
{ | { | |||
LOG_STRERROR ("strdup"); | LOG_STRERROR ("strdup"); | |||
return; | return; | |||
} | } | |||
for (prefix = strtok_r (d, PATH_SEPARATOR_STR, &saveptr); | for (prefix = strtok_r (d, ":", &saveptr); | |||
NULL != prefix; | NULL != prefix; | |||
prefix = strtok_r (NULL, PATH_SEPARATOR_STR, &saveptr)) | prefix = strtok_r (NULL, ":", &saveptr)) | |||
pp (pp_cls, prefix); | pp (pp_cls, prefix); | |||
free (d); | free (d); | |||
return; | return; | |||
} | } | |||
#if GNU_LINUX | #if GNU_LINUX | |||
if (NULL == prefix) | if (NULL == prefix) | |||
prefix = get_path_from_proc_exe (); | prefix = get_path_from_proc_exe (); | |||
#endif | #endif | |||
#if WINDOWS | #if WINDOWS | |||
if (NULL == prefix) | if (NULL == prefix) | |||
skipping to change at line 539 | skipping to change at line 538 | |||
struct SearchContext *sc = cls; | struct SearchContext *sc = cls; | |||
DIR *dir; | DIR *dir; | |||
struct dirent *ent; | struct dirent *ent; | |||
const char *sym_name; | const char *sym_name; | |||
char *sym; | char *sym; | |||
char *dot; | char *dot; | |||
size_t dlen; | size_t dlen; | |||
if (NULL != sc->path) | if (NULL != sc->path) | |||
return; | return; | |||
if (NULL == (dir = OPENDIR (path))) | if (NULL == (dir = opendir (path))) | |||
return; | return; | |||
while (NULL != (ent = READDIR (dir))) | while (NULL != (ent = readdir (dir))) | |||
{ | { | |||
if ('.' == ent->d_name[0]) | if ('.' == ent->d_name[0]) | |||
continue; | continue; | |||
dlen = strlen (ent->d_name); | dlen = strlen (ent->d_name); | |||
if ( (dlen < 4) || | if ( (dlen < 4) || | |||
( (0 != strcmp (&ent->d_name[dlen - 3], ".so")) && | ( (0 != strcmp (&ent->d_name[dlen - 3], ".so")) && | |||
(0 != strcasecmp (&ent->d_name[dlen - 4], ".dll")) ) ) | (0 != strcasecmp (&ent->d_name[dlen - 4], ".dll")) ) ) | |||
continue; /* only load '.so' and '.dll' */ | continue; /* only load '.so' and '.dll' */ | |||
if (NULL == (sym_name = strrchr (ent->d_name, '_'))) | if (NULL == (sym_name = strrchr (ent->d_name, '_'))) | |||
continue; | continue; | |||
sym_name++; | sym_name++; | |||
if (NULL == (sym = strdup (sym_name))) | if (NULL == (sym = strdup (sym_name))) | |||
{ | { | |||
LOG_STRERROR ("strdup"); | LOG_STRERROR ("strdup"); | |||
CLOSEDIR (dir); | closedir (dir); | |||
return; | return; | |||
} | } | |||
dot = strchr (sym, '.'); | dot = strchr (sym, '.'); | |||
if (NULL != dot) | if (NULL != dot) | |||
*dot = '\0'; | *dot = '\0'; | |||
if (0 == strcmp (sym, sc->short_name)) | if (0 == strcmp (sym, sc->short_name)) | |||
{ | { | |||
sc->path = append_to_dir (path, ent->d_name); | sc->path = append_to_dir (path, ent->d_name); | |||
free (sym); | free (sym); | |||
break; | break; | |||
} | } | |||
free (sym); | free (sym); | |||
} | } | |||
CLOSEDIR (dir); | closedir (dir); | |||
} | } | |||
/** | /** | |||
* Given a short name of a library (i.e. "mime"), find | * Given a short name of a library (i.e. "mime"), find | |||
* the full path of the respective plugin. | * the full path of the respective plugin. | |||
*/ | */ | |||
char * | char * | |||
EXTRACTOR_find_plugin_ (const char *short_name) | EXTRACTOR_find_plugin_ (const char *short_name) | |||
{ | { | |||
struct SearchContext sc; | struct SearchContext sc; | |||
End of changes. 9 change blocks. | ||||
9 lines changed or deleted | 8 lines changed or added |