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