Created SILC Runtime Toolkit git repository Part II.
[runtime.git] / lib / silcutil / silcdll.c
1 /*
2
3   silcdll.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2007 - 2008 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #include "silcruntime.h"
21
22 /* Load shared object */
23
24 SilcDll silc_dll_load(const char *object_path)
25 {
26 #ifdef SILC_UNIX
27 #if defined(HAVE_DLOPEN)
28 #if defined(RTLD_NOW)
29   return dlopen(object_path, RTLD_NOW);
30 #elif defined(RTLD_LAZY)
31   return dlopen(object_path, RTLD_LAZY);
32 #else
33   return dlopen(object_path, 0);
34 #endif /* RTLD_NOW */
35 #endif /* HAVE_DLOPEN */
36 #elif SILC_WIN32
37   return LoadLibrary(object_path);
38 #else
39   /* XXX Symbian */
40 #endif /* SILC_UNIX */
41   silc_set_errno_reason(SILC_ERR_NOT_SUPPORTED,
42                         "Shared objects are not supported on this platform");
43   return NULL;
44 }
45
46 /* Close shared object */
47
48 void silc_dll_close(SilcDll dll)
49 {
50 #ifdef SILC_UNIX
51 #if defined(HAVE_DLOPEN)
52   dlclose(dll);
53 #endif /* HAVE_DLOPEN */
54 #elif SILC_WIN32
55   FreeLibrary(dll);
56 #else
57   /* XXX Symbian */
58 #endif /* SILC_UNIX */
59 }
60
61 /* Get symbol address from shared object */
62
63 void *silc_dll_getsym(SilcDll dll, const char *symbol)
64 {
65 #ifdef SILC_UNIX
66 #if defined(HAVE_DLOPEN)
67   return (void *)dlsym(dll, symbol);
68 #endif /* HAVE_DLOPEN */
69 #elif SILC_WIN32
70   return (void *)GetProcAddress(dll, symbol);
71 #else
72   /* XXX Symbian */
73 #endif /* SILC_UNIX */
74   silc_set_errno_reason(SILC_ERR_NOT_SUPPORTED,
75                         "Shared objects are not supported on this platform");
76   return NULL;
77 }
78
79 /* Get error string */
80
81 const char *silc_dll_error(SilcDll dll)
82 {
83 #ifdef SILC_UNIX
84 #if defined(HAVE_DLOPEN)
85   return dlerror();
86 #endif /* HAVE_DLOPEN */
87 #elif SILC_WIN32
88   return NULL;
89 #else
90   /* XXX Symbian */
91 #endif /* SILC_UNIX */
92   return NULL;
93 }