]> git.saurik.com Git - wxWidgets.git/blob - src/unix/dl_macosx.cpp
use GetText() instead of GetText(wxString&), made some methods inline
[wxWidgets.git] / src / unix / dl_macosx.cpp
1 /* dl_macosx.c
2 *
3 * Platform: Mac OS X
4 * Author: Gilles Depeyrot (Gilles.Depeyrot@wanadoo.fr)
5 * Based on: dl_next.xs by Anno Siegel (siegel@zrz.TU-Berlin.DE)
6 * Based on: dl_dlopen.xs by Paul Marquess
7 * Created: Aug 15th, 1994
8 *
9 */
10
11 /* Porting notes:
12 * dl_macosx.c is itself a port from dl_next.xs by Anno Siegel.
13 * dl_next.xs is itself a port from dl_dlopen.xs by Paul Marquess.
14 * The method used here is just to supply the sun style dlopen etc.
15 * functions in terms of NeXTs rld_*.
16 */
17
18 #include <stdio.h>
19
20 static char dl_last_error[1024];
21
22 char *dlerror()
23 {
24 return dl_last_error;
25 }
26
27 int dlclose(void *handle) /* stub only */
28 {
29 return 0;
30 }
31
32 extern "C" {
33 #import <mach-o/dyld.h>
34 };
35
36 enum dyldErrorSource
37 {
38 OFImage,
39 };
40
41 static
42 void TranslateError(const char *path, enum dyldErrorSource type, int number)
43 {
44 unsigned int index;
45 static char *OFIErrorStrings[] =
46 {
47 "%s(%d): Object Image Load Failure\n",
48 "%s(%d): Object Image Load Success\n",
49 "%s(%d): Not an recognisable object file\n",
50 "%s(%d): No valid architecture\n",
51 "%s(%d): Object image has an invalid format\n",
52 "%s(%d): Invalid access (permissions?)\n",
53 "%s(%d): Unknown error code from NSCreateObjectFileImageFromFile\n",
54 };
55 #define NUM_OFI_ERRORS (sizeof(OFIErrorStrings) / sizeof(OFIErrorStrings[0]))
56
57 switch (type)
58 {
59 case OFImage:
60 index = number;
61 if (index > NUM_OFI_ERRORS - 1)
62 index = NUM_OFI_ERRORS - 1;
63 sprintf(dl_last_error, OFIErrorStrings[index], path, number);
64 break;
65
66 default:
67 sprintf(dl_last_error, "%s(%d): Totally unknown error type %d\n",
68 path, number, type);
69 break;
70 }
71 }
72
73 void *dlopen(const char *path, int mode /* mode is ignored */)
74 {
75 int dyld_result;
76 NSObjectFileImage ofile;
77 NSModule handle = NULL;
78
79 dyld_result = NSCreateObjectFileImageFromFile(path, &ofile);
80 if (dyld_result != NSObjectFileImageSuccess)
81 {
82 TranslateError(path, OFImage, dyld_result);
83 }
84 else
85 {
86 // NSLinkModule will cause the run to abort on any link error's
87 // not very friendly but the error recovery functionality is limited.
88 handle = NSLinkModule(ofile, path, TRUE);
89 }
90
91 return handle;
92 }
93
94 void *dlsym(void *handle, const char *symbol)
95 {
96 void *addr;
97
98 if (NSIsSymbolNameDefined(symbol))
99 addr = NSAddressOfSymbol(NSLookupAndBindSymbol(symbol));
100 else
101 addr = NULL;
102
103 return addr;
104 }