ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/linker.C
Revision: 1.3
Committed: Sat Jul 21 13:23:22 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
- added rcsid to some files
- more documentation tweaks
- made most protocol commands local to phandler.C
- added ircd metadata (inspircd only for now)
- added inspircd swhois support

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * linker.C: Abstraction of the dynamic linking system.
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6     */
7    
8 pippijn 1.3 static char const rcsid[] = "$Id$";
9 pippijn 1.1
10     #include "atheme.h"
11    
12     #include <dlfcn.h>
13    
14     #ifdef __OpenBSD__
15     # define RTLD_NOW RTLD_LAZY
16     #endif
17    
18     #ifndef __HPUX__
19     # define PLATFORM_SUFFIX ".so"
20     #else
21     # define PLATFORM_SUFFIX ".sl"
22     #endif
23    
24     /*
25     * linker_open()
26     *
27     * Inputs:
28     * path to file to open
29     *
30     * Outputs:
31     * linker handle.
32     *
33     * Side Effects:
34     * a shared module is loaded into the application's memory space
35     */
36     void *
37     linker_open (char *path)
38     {
39     return dlopen (path, RTLD_NOW);
40     }
41    
42     /*
43     * linker_open_ext()
44     *
45     * Inputs:
46     * path to file to open
47     *
48     * Outputs:
49     * linker handle
50     *
51     * Side Effects:
52     * the extension is appended if it's not already there.
53     * a shared module is loaded into the application's memory space
54     */
55     void *
56     linker_open_ext (char *path)
57     {
58     void *handle;
59     char *buf = static_cast<char *> (smalloc (strlen (path) + 20));
60    
61     strlcpy (buf, path, strlen (path) + 20);
62    
63     if (!strstr (buf, PLATFORM_SUFFIX))
64     strlcat (buf, PLATFORM_SUFFIX, strlen (path) + 20);
65    
66     handle = linker_open (buf);
67     free (buf);
68    
69     return handle;
70     }
71    
72     /*
73     * linker_getsym()
74     *
75     * Inputs:
76     * linker handle, symbol to retrieve
77     *
78     * Outputs:
79     * pointer to symbol, or NULL if no symbol.
80     *
81     * Side Effects:
82     * none
83     */
84     void *
85     linker_getsym (void *vptr, char *sym)
86     {
87     return dlsym (vptr, sym);
88     }
89    
90     /*
91     * linker_close()
92     *
93     * Inputs:
94     * linker handle
95     *
96     * Outputs:
97     * none
98     *
99     * Side Effects:
100     * the module is unloaded from the linker
101     */
102     void
103     linker_close (void *vptr)
104     {
105     dlclose (vptr);
106     }