Mercurial > hg > xemacs-beta
comparison src/sysdll.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | aabb7f5b1c81 |
children | de805c49cfc1 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
21 | 21 |
22 #ifdef HAVE_CONFIG_H | 22 #ifdef HAVE_CONFIG_H |
23 #include <config.h> | 23 #include <config.h> |
24 #endif | 24 #endif |
25 | 25 |
26 #include <stdlib.h> | |
26 #include "sysdll.h" | 27 #include "sysdll.h" |
27 | 28 |
28 /* This whole file is conditional upon HAVE_SHLIB */ | 29 /* This whole file is conditional upon HAVE_SHLIB */ |
29 #ifdef HAVE_SHLIB | 30 #ifdef HAVE_SHLIB |
30 | 31 |
46 #ifndef RTLD_GLOBAL | 47 #ifndef RTLD_GLOBAL |
47 # define RTLD_GLOBAL 0 | 48 # define RTLD_GLOBAL 0 |
48 #endif | 49 #endif |
49 | 50 |
50 int | 51 int |
51 dll_init (CONST char *arg) | 52 dll_init (const char *arg) |
52 { | 53 { |
53 return 0; | 54 return 0; |
54 } | 55 } |
55 | 56 |
56 dll_handle | 57 dll_handle |
57 dll_open (CONST char *fname) | 58 dll_open (const char *fname) |
58 { | 59 { |
59 return (dll_handle)dlopen (fname, RTLD_LAZY | RTLD_GLOBAL); | 60 return (dll_handle)dlopen (fname, RTLD_LAZY | RTLD_GLOBAL); |
60 } | 61 } |
61 | 62 |
62 int | 63 int |
64 { | 65 { |
65 return dlclose((void *)h); | 66 return dlclose((void *)h); |
66 } | 67 } |
67 | 68 |
68 dll_func | 69 dll_func |
69 dll_function (dll_handle h, CONST char *n) | 70 dll_function (dll_handle h, const char *n) |
70 { | 71 { |
71 #ifdef DLSYM_NEEDS_UNDERSCORE | 72 #ifdef DLSYM_NEEDS_UNDERSCORE |
72 char *buf = alloca_array (char, strlen (n) + 2); | 73 char *buf = alloca_array (char, strlen (n) + 2); |
73 *buf = '_'; | 74 *buf = '_'; |
74 (void)strcpy(buf + 1, n); | 75 (void)strcpy(buf + 1, n); |
76 #endif | 77 #endif |
77 return (dll_func)dlsym ((void *)h, n); | 78 return (dll_func)dlsym ((void *)h, n); |
78 } | 79 } |
79 | 80 |
80 dll_var | 81 dll_var |
81 dll_variable (dll_handle h, CONST char *n) | 82 dll_variable (dll_handle h, const char *n) |
82 { | 83 { |
83 #ifdef DLSYM_NEEDS_UNDERSCORE | 84 #ifdef DLSYM_NEEDS_UNDERSCORE |
84 char *buf = alloca_array (char, strlen (n) + 2); | 85 char *buf = alloca_array (char, strlen (n) + 2); |
85 *buf = '_'; | 86 *buf = '_'; |
86 (void)strcpy(buf + 1, n); | 87 (void)strcpy(buf + 1, n); |
87 n = buf; | 88 n = buf; |
88 #endif | 89 #endif |
89 return (dll_var)dlsym ((void *)h, n); | 90 return (dll_var)dlsym ((void *)h, n); |
90 } | 91 } |
91 | 92 |
92 CONST char * | 93 const char * |
93 dll_error (dll_handle h) | 94 dll_error (dll_handle h) |
94 { | 95 { |
95 #if defined(HAVE_DLERROR) || defined(dlerror) | 96 #if defined(HAVE_DLERROR) || defined(dlerror) |
96 return (CONST char *)dlerror (); | 97 return (const char *)dlerror (); |
97 #elif defined(HAVE__DLERROR) | 98 #elif defined(HAVE__DLERROR) |
98 return (const char *)_dlerror(); | 99 return (const char *)_dlerror(); |
99 #else | 100 #else |
100 return "Shared library error"; | 101 return "Shared library error"; |
101 #endif | 102 #endif |
103 | 104 |
104 #elif defined(HAVE_SHL_LOAD) | 105 #elif defined(HAVE_SHL_LOAD) |
105 /* This is the HP/UX version */ | 106 /* This is the HP/UX version */ |
106 #include <dl.h> | 107 #include <dl.h> |
107 int | 108 int |
108 dll_init (CONST char *arg) | 109 dll_init (const char *arg) |
109 { | 110 { |
110 return 0; | 111 return 0; |
111 } | 112 } |
112 | 113 |
113 dll_handle | 114 dll_handle |
114 dll_open (CONST char *fname) | 115 dll_open (const char *fname) |
115 { | 116 { |
116 shl_t h = shl_load (fname, BIND_DEFERRED,0L); | 117 shl_t h = shl_load (fname, BIND_DEFERRED,0L); |
117 shl_t *hp = NULL; | 118 shl_t *hp = NULL; |
118 | 119 |
119 if (h) | 120 if (h) |
134 free (hp); | 135 free (hp); |
135 return shl_unload(h); | 136 return shl_unload(h); |
136 } | 137 } |
137 | 138 |
138 dll_func | 139 dll_func |
139 dll_function (dll_handle h, CONST char *n) | 140 dll_function (dll_handle h, const char *n) |
140 { | 141 { |
141 long handle = 0L; | 142 long handle = 0L; |
142 | 143 |
143 if (shl_findsym ((shl_t *)h, n, TYPE_PROCEDURE, &handle)) | 144 if (shl_findsym ((shl_t *)h, n, TYPE_PROCEDURE, &handle)) |
144 return NULL; | 145 return NULL; |
145 | 146 |
146 return (dll_func)handle; | 147 return (dll_func)handle; |
147 } | 148 } |
148 | 149 |
149 dll_var | 150 dll_var |
150 dll_variable (dll_handle h, CONST char *n) | 151 dll_variable (dll_handle h, const char *n) |
151 { | 152 { |
152 long handle = 0L; | 153 long handle = 0L; |
153 | 154 |
154 if (shl_findsym ((shl_t *)h, n, TYPE_DATA, &handle)) | 155 if (shl_findsym ((shl_t *)h, n, TYPE_DATA, &handle)) |
155 return NULL; | 156 return NULL; |
156 | 157 |
157 return (dll_var)handle; | 158 return (dll_var)handle; |
158 } | 159 } |
159 | 160 |
160 CONST char * | 161 const char * |
161 dll_error (dll_handle h) | 162 dll_error (dll_handle h) |
162 { | 163 { |
163 /* #### WTF?! Shouldn't this at least attempt to get strerror or | 164 /* #### WTF?! Shouldn't this at least attempt to get strerror or |
164 something? --hniksic */ | 165 something? --hniksic */ |
165 return "Generic shared library error"; | 166 return "Generic shared library error"; |
166 } | 167 } |
167 | 168 |
168 #elif defined(HAVE_INIT_DLD) | 169 #elif defined(HAVE_INIT_DLD) |
169 #include <dld.h> | 170 #include <dld.h> |
170 int | 171 int |
171 dll_init (CONST char *arg) | 172 dll_init (const char *arg) |
172 { | 173 { |
173 char *real_exe = dld_find_executable (arg); | 174 char *real_exe = dld_find_executable (arg); |
174 int rc; | 175 int rc; |
175 | 176 |
176 rc = dld_init (real_exe); | 177 rc = dld_init (real_exe); |
181 } | 182 } |
182 return 0; | 183 return 0; |
183 } | 184 } |
184 | 185 |
185 dll_handle | 186 dll_handle |
186 dll_open (CONST char *fname) | 187 dll_open (const char *fname) |
187 { | 188 { |
188 rc = dld_link (fname); | 189 rc = dld_link (fname); |
189 if (rc) | 190 if (rc) |
190 return NULL; | 191 return NULL; |
191 | 192 |
203 */ | 204 */ |
204 return 1; | 205 return 1; |
205 } | 206 } |
206 | 207 |
207 DLL_FUNC | 208 DLL_FUNC |
208 dll_function (dll_handle h, CONST char *n) | 209 dll_function (dll_handle h, const char *n) |
209 { | 210 { |
210 return dld_get_func(n); | 211 return dld_get_func(n); |
211 } | 212 } |
212 | 213 |
213 DLL_FUNC | 214 DLL_FUNC |
214 dll_variable (dll_handle h, CONST char *n) | 215 dll_variable (dll_handle h, const char *n) |
215 { | 216 { |
216 return dld_get_symbol(n); | 217 return dld_get_symbol(n); |
217 } | 218 } |
218 #elif defined(_WINDOWS) || defined(WIN32) | 219 #elif defined(_WINDOWS) || defined(WIN32) |
219 int | 220 int |
220 dll_init (CONST char *arg) | 221 dll_init (const char *arg) |
221 { | 222 { |
222 return 0; | 223 return 0; |
223 } | 224 } |
224 | 225 |
225 dll_handle | 226 dll_handle |
226 dll_open (CONST char *fname) | 227 dll_open (const char *fname) |
227 { | 228 { |
228 return (dll_handle)LoadLibrary (fname); | 229 return (dll_handle)LoadLibrary (fname); |
229 } | 230 } |
230 | 231 |
231 int | 232 int |
233 { | 234 { |
234 return FreeLibrary (h); | 235 return FreeLibrary (h); |
235 } | 236 } |
236 | 237 |
237 dll_func | 238 dll_func |
238 dll_function (dll_handle h, CONST char *n) | 239 dll_function (dll_handle h, const char *n) |
239 { | 240 { |
240 return (dll_func)GetProcAddress (h,n); | 241 return (dll_func)GetProcAddress (h,n); |
241 } | 242 } |
242 | 243 |
243 dll_func | 244 dll_func |
244 dll_variable (dll_handle h, CONST char *n) | 245 dll_variable (dll_handle h, const char *n) |
245 { | 246 { |
246 return (dll_func)GetProcAddress (h,n); | 247 return (dll_func)GetProcAddress (h,n); |
247 } | 248 } |
248 | 249 |
249 CONST char * | 250 const char * |
250 dll_error (dll_handle h) | 251 dll_error (dll_handle h) |
251 { | 252 { |
252 return "Windows DLL Error"; | 253 return "Windows DLL Error"; |
253 } | 254 } |
254 #else | 255 #else |
255 /* Catchall if we don't know about this systems method of dynamic loading */ | 256 /* Catchall if we don't know about this systems method of dynamic loading */ |
256 int | 257 int |
257 dll_init (CONST char *arg) | 258 dll_init (const char *arg) |
258 { | 259 { |
259 return -1; | 260 return -1; |
260 } | 261 } |
261 | 262 |
262 dll_handle | 263 dll_handle |
263 dll_open (CONST char *fname) | 264 dll_open (const char *fname) |
264 { | 265 { |
265 return NULL; | 266 return NULL; |
266 } | 267 } |
267 | 268 |
268 int | 269 int |
270 { | 271 { |
271 return 0; | 272 return 0; |
272 } | 273 } |
273 | 274 |
274 dll_func | 275 dll_func |
275 dll_function (dll_handle h, CONST char *n) | 276 dll_function (dll_handle h, const char *n) |
276 { | 277 { |
277 return NULL; | 278 return NULL; |
278 } | 279 } |
279 | 280 |
280 dll_func | 281 dll_func |
281 dll_variable (dll_handle h, CONST char *n) | 282 dll_variable (dll_handle h, const char *n) |
282 { | 283 { |
283 return NULL; | 284 return NULL; |
284 } | 285 } |
285 | 286 |
286 CONST char * | 287 const char * |
287 dll_error (dll_handle h) | 288 dll_error (dll_handle h) |
288 { | 289 { |
289 return "Shared libraries not implemented on this system"; | 290 return "Shared libraries not implemented on this system"; |
290 } | 291 } |
291 #endif /* System conditionals */ | 292 #endif /* System conditionals */ |