r25859: Wrap native HPUX functions in dl implementation.
[jelmer/samba4-debian.git] / source / lib / replace / dlfcn.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Samba system utilities
4    Copyright (C) Andrew Tridgell 1992-1998
5    Copyright (C) Jeremy Allison 1998-2002
6
7      ** NOTE! The following LGPL license applies to the replace
8      ** library. This does NOT imply that all of Samba is released
9      ** under the LGPL
10    
11    This library is free software; you can redistribute it and/or
12    modify it under the terms of the GNU Lesser General Public
13    License as published by the Free Software Foundation; either
14    version 3 of the License, or (at your option) any later version.
15
16    This library 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 GNU
19    Lesser General Public License for more details.
20
21    You should have received a copy of the GNU Lesser General Public
22    License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 */
24
25 #include "replace.h"
26 #ifdef HAVE_DL_H
27 #include <dl.h>
28 #endif
29
30 #ifndef HAVE_DLOPEN
31 #ifdef DLOPEN_TAKES_UNSIGNED_FLAGS
32 void *rep_dlopen(const char *name, unsigned int flags)
33 #else
34 void *rep_dlopen(const char *name, int flags)
35 #endif
36 {
37 #ifdef HAVE_SHL_LOAD
38         return (void *)shl_load(name, flags, 0);
39 #else
40         return NULL;
41 #endif
42 }
43 #endif
44
45 #ifndef HAVE_DLSYM
46 void *rep_dlsym(void *handle, const char *symbol)
47 {
48 #ifdef HAVE_SHL_FINDSYM
49         void *sym_addr;
50         if (!shl_findsym((shl_t *)&handle, symbol, TYPE_UNDEFINED, &sym_addr))
51                 return sym_addr;
52 #endif
53     return NULL;
54 }
55 #endif
56
57 #ifndef HAVE_DLERROR
58 char *rep_dlerror(void)
59 {
60         return "dynamic loading of objects not supported on this platform";
61 }
62 #endif
63
64 #ifndef HAVE_DLCLOSE
65 int rep_dlclose(void *handle)
66 {
67 #ifdef HAVE_SHL_CLOSE
68         return shl_unload((shl_t)handle);
69 #else
70         return 0;
71 #endif
72 }
73 #endif