2012-12-19 11:59:59 +00:00
|
|
|
/*
|
2016-10-31 16:05:24 +00:00
|
|
|
* ltdl.c - ltdl emulation for android
|
|
|
|
* Copyright (C) 2012 Ladislav Vaiz <ok1zia@nagano.cz>
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2012-12-19 11:59:59 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <ltdl.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2021-02-28 05:13:29 +00:00
|
|
|
#include <stdlib.h>
|
2012-12-19 11:59:59 +00:00
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
#include <android/log.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define APREFIX "lib"
|
|
|
|
#define ASUFFIX ".so"
|
|
|
|
#define AMAXSTR 1024
|
|
|
|
#define ASONAME "libhamlib.so"
|
|
|
|
|
|
|
|
// path to application's libraries with trailing slash
|
|
|
|
char *libpath = NULL;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
char *getlibpath(void)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
char s[AMAXSTR];
|
|
|
|
FILE *f;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (libpath != NULL) { return libpath; }
|
2012-12-19 11:59:59 +00:00
|
|
|
|
|
|
|
f = fopen("/proc/self/maps", "rt");
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!f) { return "./"; }
|
|
|
|
|
|
|
|
while (fgets(s, AMAXSTR - 1, f))
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
char *c;
|
|
|
|
|
|
|
|
s[AMAXSTR - 1] = '\0';
|
|
|
|
c = strstr(s, ASONAME);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (!c) { continue; }
|
2012-12-19 11:59:59 +00:00
|
|
|
|
|
|
|
// s is like "4a8a5000-4a8a6000 r--p 00018000 1f:01 743 /data/data/cz.nagano.tucnak/lib/libhamlib.so\n"
|
|
|
|
*c = '\0';
|
|
|
|
c = strchr(s, '/');
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (!c) { continue; }
|
|
|
|
|
2012-12-19 11:59:59 +00:00
|
|
|
libpath = malloc(strlen(c) + 1);
|
|
|
|
strcpy(libpath, c);
|
|
|
|
break;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2012-12-19 11:59:59 +00:00
|
|
|
fclose(f);
|
|
|
|
return libpath;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:19:10 +00:00
|
|
|
#ifdef XXREMOVEDXX
|
|
|
|
// Not referenced anywhere
|
2019-11-30 16:19:08 +00:00
|
|
|
int lt_dlinit(void)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlinit");
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-08 05:19:10 +00:00
|
|
|
#endif
|
2012-12-19 11:59:59 +00:00
|
|
|
|
|
|
|
// not called from hamlib
|
2019-12-08 05:19:10 +00:00
|
|
|
#ifdef XXREMOVEDXX
|
|
|
|
// Not referenced anywhere
|
2019-11-30 16:19:08 +00:00
|
|
|
int lt_dlexit(void)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlexit");
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (libpath != NULL)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
free(libpath);
|
|
|
|
libpath = NULL;
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2012-12-19 11:59:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-12-08 05:19:10 +00:00
|
|
|
#endif
|
2012-12-19 11:59:59 +00:00
|
|
|
|
2019-12-08 05:20:31 +00:00
|
|
|
#ifdef XXREMOVEDXX
|
2019-11-30 16:19:08 +00:00
|
|
|
int lt_dladdsearchdir(const char *search_dir)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dladdsearchdir");
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-08 05:20:31 +00:00
|
|
|
#endif
|
2012-12-19 11:59:59 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
lt_dlhandle adlopen(const char *filename)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
char *c;
|
|
|
|
lt_dlhandle *ret;
|
|
|
|
|
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "adlopen('%s')", filename);
|
|
|
|
getlibpath();
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (libpath == NULL || filename == NULL) { return NULL; }
|
|
|
|
|
|
|
|
c = malloc(strlen(libpath) + strlen(APREFIX) + strlen(filename) + strlen(
|
|
|
|
ASUFFIX) + 1);
|
2012-12-19 11:59:59 +00:00
|
|
|
strcpy(c, libpath);
|
|
|
|
strcat(c, APREFIX);
|
|
|
|
strcat(c, filename);
|
|
|
|
strcat(c, ASUFFIX);
|
|
|
|
|
|
|
|
ret = dlopen(c, 0);
|
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "adlopen('%s')=%p", c, ret);
|
|
|
|
free(c);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:19:10 +00:00
|
|
|
#ifdef XXREMOVEDXX
|
|
|
|
// Not referenced anywhere
|
2019-11-30 16:19:08 +00:00
|
|
|
lt_dlhandle lt_dlopen(const char *filename)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlopen(%s)", filename);
|
|
|
|
return adlopen(filename);
|
|
|
|
}
|
2019-12-08 05:19:10 +00:00
|
|
|
#endif
|
2012-12-19 11:59:59 +00:00
|
|
|
|
2019-12-08 05:19:10 +00:00
|
|
|
#ifdef XXREMOVEDXX
|
|
|
|
// Not referenced anywhere
|
2019-11-30 16:19:08 +00:00
|
|
|
lt_dlhandle lt_dlopenext(const char *filename)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlopenext(%s)", filename);
|
|
|
|
return adlopen(filename);
|
|
|
|
}
|
2019-12-08 05:19:10 +00:00
|
|
|
#endif
|
2012-12-19 11:59:59 +00:00
|
|
|
|
2019-12-08 05:19:10 +00:00
|
|
|
#ifdef XXREMOVEDXX
|
|
|
|
// Not referenced anywhere
|
2019-11-30 16:19:08 +00:00
|
|
|
int lt_dlclose(lt_dlhandle handle)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlclose");
|
|
|
|
return dlclose(handle);
|
|
|
|
}
|
2019-12-08 05:19:10 +00:00
|
|
|
#endif
|
2012-12-19 11:59:59 +00:00
|
|
|
|
2019-12-08 05:19:10 +00:00
|
|
|
#ifdef XXREMOVEDXX
|
|
|
|
// Not referenced anywhere
|
2019-11-30 16:19:08 +00:00
|
|
|
void *lt_dlsym(lt_dlhandle handle, const char *name)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
void *ret = dlsym(handle, name);
|
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlsym(%s)=%p", name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-12-08 05:19:10 +00:00
|
|
|
#endif
|
2012-12-19 11:59:59 +00:00
|
|
|
|
2019-12-08 05:19:10 +00:00
|
|
|
#ifdef XXREMOVEDXX
|
|
|
|
// Not referenced anywhere
|
2019-11-30 16:19:08 +00:00
|
|
|
const char *lt_dlerror(void)
|
|
|
|
{
|
2012-12-19 11:59:59 +00:00
|
|
|
const char *ret = dlerror();
|
|
|
|
// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlerror=%s", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-12-08 05:19:10 +00:00
|
|
|
#endif
|