]> code.citadel.org Git - citadel.git/blob - citadel/hpsux.h
* Merged in IO ERROR's diffs to make Citadel work with HP/UX
[citadel.git] / citadel / hpsux.h
1 /* $Id$ */
2
3 /* This nice file makes Citadel/UX work with HP/UX's dynamic loader. */
4 /* It's unusual to put C code in a .h file, but I think it's easier for the
5    moment.  */
6
7 #ifndef _CITADEL_UX_HPSUX_H
8 #define _CITADEL_UX_HPSUX_H
9
10 /* includes */
11 #include <errno.h>
12 #include <dl.h>
13 #include <string.h>
14
15
16 /* functions */
17 void *dlopen(const char *, int);
18 int dlclose(void *);
19 const char *dlerror(void);
20 void *dlsym(void *, char *);
21
22
23 /* #defines mapped */
24
25 #define RTLD_LAZY       BIND_DEFERRED
26 #define RTLD_NOW        BIND_IMMEDIATE
27 #define RTLD_GLOBAL     0       /* This SEEMS to be the default for HP/UX */
28
29
30 /* extern variables */
31 extern int errno;
32
33
34 /* local variables */
35 static char *dlerrmsg;  /* pointer to last error message */
36
37
38 /* functions mapped */
39
40 /* dlopen() */
41 void *dlopen(const char *filename, int flag)
42 {
43         shl_t handle;
44
45         handle = shl_load(filename, flag, 0L);
46         if (handle == NULL)
47                 dlerrmsg = strerror(errno);
48         return (void *)handle;
49 }
50
51 /* dlclose() */
52 int dlclose(void *handle)
53 {
54         return shl_unload(handle);
55 }
56
57 /* dlerror() */
58 /* I think this is as thread safe as it's going to get */
59 const char *dlerror(void)
60 {
61         const char *msg;
62
63         msg = dlerrmsg;
64         dlerrmsg = NULL;
65         return msg;
66 }
67
68 /* dlsym() */
69 void *dlsym(void *handle, char *symbol)
70 {
71         void *value = NULL;     /* Linux man page says 0 is a valid symbol */
72         /* address.  I don't understand this, of course, but what do I know? */
73
74         if (shl_findsym(handle, symbol, TYPE_UNDEFINED, value) == -1)
75                 dlerrmsg = strerror(errno);
76         return value;
77 }
78
79 #endif /* _CITADEL_UX_HPSUX_H */