1 /** \file dynlib-unix.c
2 * \brief Unix support for dynamic library loading
3 *
4 * \author Christian Vogelgsang <chris@vogelgsang.org>
5 */
6
7 /*
8 * This file is part of VICE, the Versatile Commodore Emulator.
9 * See README for copyright notice.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 * 02111-1307 USA.
25 *
26 */
27
28 #include <stdlib.h>
29 #include "dynlib.h"
30
31 #ifdef HAVE_DYNLIB_SUPPORT
32
33 #include <dlfcn.h>
34
35 #ifndef RTLD_LOCAL
36 #define RTLD_LOCAL 0
37 #endif
38
vice_dynlib_open(const char * name)39 void *vice_dynlib_open(const char *name)
40 {
41 return dlopen(name, RTLD_LAZY | RTLD_LOCAL);
42 }
43
vice_dynlib_symbol(void * handle,const char * name)44 void *vice_dynlib_symbol(void *handle,const char *name)
45 {
46 return dlsym(handle, name);
47 }
48
vice_dynlib_error(void)49 char *vice_dynlib_error(void)
50 {
51 char *error = dlerror();
52
53 return error ? error : "no error";
54 }
55
vice_dynlib_close(void * handle)56 int vice_dynlib_close(void *handle)
57 {
58 return dlclose(handle);
59 }
60
61 #else
62
vice_dynlib_open(const char * name)63 void *vice_dynlib_open(const char *name)
64 {
65 return NULL;
66 }
67
vice_dynlib_symbol(void * handle,const char * name)68 void *vice_dynlib_symbol(void *handle,const char *name)
69 {
70 return NULL;
71 }
72
vice_dynlib_error(void)73 char *vice_dynlib_error(void)
74 {
75 return "no error";
76 }
77
vice_dynlib_close(void * handle)78 int vice_dynlib_close(void *handle)
79 {
80 return -1;
81 }
82
83 #endif
84