Mercurial > hg > xemacs-beta
comparison src/sysdll.c @ 276:6330739388db r21-0b36
Import from CVS: tag r21-0b36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:30:37 +0200 |
parents | c5d627a313b1 |
children | 8626e4521993 |
comparison
equal
deleted
inserted
replaced
275:a68ae4439f57 | 276:6330739388db |
---|---|
42 */ | 42 */ |
43 #if defined(HAVE_DLOPEN) || defined(HAVE__DLOPEN) | 43 #if defined(HAVE_DLOPEN) || defined(HAVE__DLOPEN) |
44 #include <dlfcn.h> | 44 #include <dlfcn.h> |
45 | 45 |
46 #ifndef RTLD_LAZY | 46 #ifndef RTLD_LAZY |
47 #define RTLD_LAZY 1 | 47 # define RTLD_LAZY 1 |
48 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */ | 48 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */ |
49 | 49 |
50 #ifndef RTLD_GLOBAL | 50 #ifndef RTLD_GLOBAL |
51 #define RTLD_GLOBAL 0 | 51 # define RTLD_GLOBAL 0 |
52 #endif | 52 #endif |
53 | 53 |
54 int dll_init(CONST char *arg) { | 54 int |
55 return(0); | 55 dll_init (CONST char *arg) |
56 } | 56 { |
57 | 57 return 0; |
58 dll_handle dll_open(CONST char *fname) { | 58 } |
59 return((dll_handle)dlopen(fname,RTLD_LAZY|RTLD_GLOBAL)); | 59 |
60 } | 60 dll_handle |
61 | 61 dll_open (CONST char *fname) |
62 int dll_close(dll_handle h) { | 62 { |
63 return(dlclose((void *)h)); | 63 return (dll_handle)dlopen (fname, RTLD_LAZY | RTLD_GLOBAL); |
64 } | 64 } |
65 | 65 |
66 dll_func dll_function(dll_handle h,CONST char *n) { | 66 int |
67 dll_close (dll_handle h) | |
68 { | |
69 return dlclose((void *)h); | |
70 } | |
71 | |
72 dll_func | |
73 dll_function (dll_handle h, CONST char *n) | |
74 { | |
67 #ifdef DLSYM_NEEDS_UNDERSCORE | 75 #ifdef DLSYM_NEEDS_UNDERSCORE |
68 char buf[1024]; | 76 char *buf = alloca_array (char, strlen (n) + 2); |
69 *buf = '_'; | 77 *buf = '_'; |
70 (void)strcpy(buf + 1, n); | 78 (void)strcpy(buf + 1, n); |
71 n = buf; | 79 n = buf; |
72 #endif | 80 #endif |
73 return((dll_func)dlsym((void *)h,n)); | 81 return (dll_func)dlsym ((void *)h, n); |
74 } | 82 } |
75 | 83 |
76 dll_var dll_variable(dll_handle h,CONST char *n) { | 84 dll_var |
77 return((dll_var)dlsym((void *)h,n)); | 85 dll_variable (dll_handle h, CONST char *n) |
78 } | 86 { |
79 | 87 return (dll_var)dlsym ((void *)h, n); |
80 CONST char *dll_error(dll_handle h) { | 88 } |
89 | |
90 CONST char * | |
91 dll_error (dll_handle h) | |
92 { | |
81 #ifdef HAVE_DLERROR | 93 #ifdef HAVE_DLERROR |
82 return((CONST char *)dl_error()); | 94 return (CONST char *)dlerror (); |
83 #else | 95 #else |
84 return("Shared library error"); | 96 return "Shared library error"; |
85 #endif | 97 #endif |
86 } | 98 } |
87 | 99 |
88 #elif defined(HAVE_SHL_LOAD) | 100 #elif defined(HAVE_SHL_LOAD) |
89 /* This is the HP/UX version */ | 101 /* This is the HP/UX version */ |
90 #include <dl.h> | 102 #include <dl.h> |
91 int dll_init(CONST char *arg) { | 103 int |
92 return(0); | 104 dll_init (CONST char *arg) |
93 } | 105 { |
94 | 106 return 0; |
95 dll_handle dll_open(CONST char *fname) { | 107 } |
96 shl_t h = shl_load(fname,BIND_DEFERRED,0L); | 108 |
109 dll_handle | |
110 dll_open (CONST char *fname) | |
111 { | |
112 shl_t h = shl_load (fname, BIND_DEFERRED,0L); | |
97 shl_t *hp = NULL; | 113 shl_t *hp = NULL; |
98 | 114 |
99 if (h) { | 115 if (h) |
100 hp = (shl_t *)malloc(sizeof(shl_t)); | 116 { |
101 if (!hp) { | 117 hp = (shl_t *)malloc (sizeof (shl_t)); |
102 shl_unload(h); | 118 if (!hp) |
103 } else { | 119 shl_unload(h); |
104 *hp = h; | 120 else |
121 *hp = h; | |
105 } | 122 } |
106 } | 123 return (dll_handle)hp; |
107 return((dll_handle)hp); | 124 } |
108 } | 125 |
109 | 126 int |
110 int dll_close(dll_handle h) { | 127 dll_close (dll_handle h) |
128 { | |
111 shl_t hp = *((shl_t *)h); | 129 shl_t hp = *((shl_t *)h); |
112 free(hp); | 130 free (hp); |
113 return (shl_unload(h)); | 131 return shl_unload(h); |
114 } | 132 } |
115 | 133 |
116 dll_func dll_function(dll_handle h,CONST char *n) { | 134 dll_func |
135 dll_function (dll_handle h, CONST char *n) | |
136 { | |
117 long handle = 0L; | 137 long handle = 0L; |
118 | 138 |
119 if (shl_findsym((shl_t *)h,n,TYPE_PROCEDURE,&handle)) | 139 if (shl_findsym ((shl_t *)h, n, TYPE_PROCEDURE, &handle)) |
120 return(NULL); | 140 return NULL; |
121 | 141 |
122 return((dll_func)handle); | 142 return (dll_func)handle; |
123 } | 143 } |
124 | 144 |
125 dll_var dll_variable(dll_handle h,CONST char *n) { | 145 dll_var |
146 dll_variable (dll_handle h, CONST char *n) | |
147 { | |
126 long handle = 0L; | 148 long handle = 0L; |
127 | 149 |
128 if (shl_findsym((shl_t *)h,n,TYPE_DATA,&handle)) | 150 if (shl_findsym ((shl_t *)h, n, TYPE_DATA, &handle)) |
129 return(NULL); | 151 return NULL; |
130 | 152 |
131 return((dll_var)handle); | 153 return (dll_var)handle; |
132 } | 154 } |
133 | 155 |
134 CONST char *dll_error(dll_handle h) { | 156 CONST char * |
135 return("Generic shared library error"); | 157 dll_error (dll_handle h) |
158 { | |
159 /* #### WTF?! Shouldn't this at least attempt to get strerror or | |
160 something? --hniksic */ | |
161 return "Generic shared library error"; | |
136 } | 162 } |
137 | 163 |
138 #elif defined(HAVE_INIT_DLD) | 164 #elif defined(HAVE_INIT_DLD) |
139 #include <dld.h> | 165 #include <dld.h> |
140 int dll_init(CONST char *arg) { | 166 int |
141 char *real_exe = dld_find_executable(arg); | 167 dll_init (CONST char *arg) |
168 { | |
169 char *real_exe = dld_find_executable (arg); | |
142 int rc; | 170 int rc; |
143 | 171 |
144 rc = dld_init(real_exe); | 172 rc = dld_init (real_exe); |
145 if (rc) { | 173 if (rc) |
146 dld_perror (exe); | 174 { |
147 return(-1); | 175 dld_perror (exe); |
148 } | 176 return -1; |
149 return(0); | 177 } |
150 } | 178 return 0; |
151 | 179 } |
152 dll_handle dll_open(CONST char *fname) { | 180 |
153 rc = dld_link(fname); | 181 dll_handle |
154 if (rc) { | 182 dll_open (CONST char *fname) |
155 return (NULL); | 183 { |
156 } | 184 rc = dld_link (fname); |
157 return((dll_handle)1); | 185 if (rc) |
158 } | 186 return NULL; |
159 | 187 |
160 int dll_close(dll_handle h) { | 188 return (dll_handle)1; |
189 } | |
190 | |
191 int | |
192 dll_close (dll_handle h) | |
193 { | |
161 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use | 194 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use |
162 ** later on to free the file - you have to remember the filename and | 195 ** later on to free the file - you have to remember the filename and |
163 ** use that as the unlinker. We should eventually keep a linked list | 196 ** use that as the unlinker. We should eventually keep a linked list |
164 ** of loaded modules and then use the node pointer as the unique id | 197 ** of loaded modules and then use the node pointer as the unique id |
165 ** for the shared library. Wheeee. But not now. | 198 ** for the shared library. Wheeee. But not now. |
166 */ | 199 */ |
167 return(1); | 200 return 1; |
168 } | 201 } |
169 | 202 |
170 DLL_FUNC dll_function(dll_handle h,CONST char *n) { | 203 DLL_FUNC |
171 return (dld_get_func(n)); | 204 dll_function (dll_handle h, CONST char *n) |
172 } | 205 { |
173 | 206 return dld_get_func(n); |
174 DLL_FUNC dll_variable(dll_handle h,CONST char *n) { | 207 } |
175 return (dld_get_symbol(n)); | 208 |
209 DLL_FUNC | |
210 dll_variable (dll_handle h, CONST char *n) | |
211 { | |
212 return dld_get_symbol(n); | |
176 } | 213 } |
177 #elif defined(_WINDOWS) || defined(WIN32) | 214 #elif defined(_WINDOWS) || defined(WIN32) |
178 int dll_init(CONST char *arg) { | 215 int |
179 return(0); | 216 dll_init (CONST char *arg) |
180 } | 217 { |
181 | 218 return 0; |
182 dll_handle dll_open(CONST char *fname) { | 219 } |
183 return((dll_handle)LoadLibrary(fname)); | 220 |
184 } | 221 dll_handle |
185 | 222 dll_open (CONST char *fname) |
186 int dll_close(dll_handle h) { | 223 { |
187 return(FreeLibrary(h)); | 224 return (dll_handle)LoadLibrary (fname); |
188 } | 225 } |
189 | 226 |
190 dll_func dll_function(dll_handle h,CONST char *n) { | 227 int |
191 return((dll_func)GetProcAddress(h,n)); | 228 dll_close (dll_handle h) |
192 } | 229 { |
193 | 230 return FreeLibrary (h); |
194 dll_func dll_variable(dll_handle h,CONST char *n) { | 231 } |
195 return((dll_func)GetProcAddress(h,n)); | 232 |
196 } | 233 dll_func |
197 | 234 dll_function (dll_handle h, CONST char *n) |
198 CONST char *dll_error(dll_handle h) { | 235 { |
199 return("Windows DLL Error"); | 236 return (dll_func)GetProcAddress (h,n); |
237 } | |
238 | |
239 dll_func | |
240 dll_variable (dll_handle h, CONST char *n) | |
241 { | |
242 return (dll_func)GetProcAddress (h,n); | |
243 } | |
244 | |
245 CONST char * | |
246 dll_error (dll_handle h) | |
247 { | |
248 return "Windows DLL Error"; | |
200 } | 249 } |
201 #else | 250 #else |
202 /* 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 */ |
203 int dll_init(CONST char *arg) { | 252 int |
204 return(-1); | 253 dll_init (CONST char *arg) |
205 } | 254 { |
206 | 255 return -1; |
207 dll_handle dll_open(CONST char *fname) { | 256 } |
208 return(NULL); | 257 |
209 } | 258 dll_handle |
210 | 259 dll_open (CONST char *fname) |
211 int dll_close(dll_handle h) { | 260 { |
212 return(0); | 261 return NULL; |
213 } | 262 } |
214 | 263 |
215 dll_func dll_function(dll_handle h,CONST char *n) { | 264 int |
216 return(NULL); | 265 dll_close (dll_handle h) |
217 } | 266 { |
218 | 267 return 0; |
219 dll_func dll_variable(dll_handle h,CONST char *n) { | 268 } |
220 return(NULL); | 269 |
221 } | 270 dll_func |
222 | 271 dll_function (dll_handle h, CONST char *n) |
223 CONST char *dll_error(dll_handle h) { | 272 { |
224 return("Shared libraries not implemented on this system."); | 273 return NULL; |
274 } | |
275 | |
276 dll_func | |
277 dll_variable (dll_handle h, CONST char *n) | |
278 { | |
279 return NULL; | |
280 } | |
281 | |
282 CONST char * | |
283 dll_error (dll_handle h) | |
284 { | |
285 return "Shared libraries not implemented on this system"; | |
225 } | 286 } |
226 #endif /* System conditionals */ | 287 #endif /* System conditionals */ |
227 | 288 |
228 #endif /* HAVE_SHLIB */ | 289 #endif /* HAVE_SHLIB */ |