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