comparison src/loadso/macos/SDL_sysloadso.c @ 1361:19418e4422cb

New configure-based build system. Still work in progress, but much improved
author Sam Lantinga <slouken@libsdl.org>
date Thu, 16 Feb 2006 10:11:48 +0000
parents
children c0a74f199ecf
comparison
equal deleted inserted replaced
1360:70a9cfb4cf1b 1361:19418e4422cb
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 /* System dependent library loading routines */
25
26 #include <stdio.h>
27 #include <string.h>
28 #define OLDP2C 1
29 #include <Strings.h>
30 #include <CodeFragments.h>
31 #include <Errors.h>
32
33 #include "SDL_loadso.h"
34
35 void *SDL_LoadObject(const char *sofile)
36 {
37 void *handle = NULL;
38 const char *loaderror = NULL;
39 CFragConnectionID library_id;
40 Ptr mainAddr;
41 Str255 errName;
42 OSErr error;
43 char psofile[512];
44
45 SDL_strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
46 psofile[SDL_TABLESIZE(psofile)-1] = '\0';
47 error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
48 kLoadCFrag, &library_id, &mainAddr, errName);
49 switch (error) {
50 case noErr:
51 loaderror = NULL;
52 break;
53 case cfragNoLibraryErr:
54 loaderror = "Library not found";
55 break;
56 case cfragUnresolvedErr:
57 loaderror = "Unabled to resolve symbols";
58 break;
59 case cfragNoPrivateMemErr:
60 case cfragNoClientMemErr:
61 loaderror = "Out of memory";
62 break;
63 default:
64 loaderror = "Unknown Code Fragment Manager error";
65 break;
66 }
67 if ( loaderror == NULL ) {
68 handle = (void *)(library_id);
69 } else {
70 SDL_SetError("Failed loading %s: %s", sofile, loaderror);
71 }
72 return(handle);
73 }
74
75 void *SDL_LoadFunction(void *handle, const char *name)
76 {
77 void *symbol = NULL;
78 const char *loaderror = NULL;
79 CFragSymbolClass class;
80 CFragConnectionID library_id = (CFragConnectionID)handle;
81 char pname[512];
82
83 SDL_strncpy(pname, name, SDL_TABLESIZE(pname));
84 pname[SDL_TABLESIZE(pname)-1] = '\0';
85 if ( FindSymbol(library_id, C2PStr(pname),
86 (char **)&symbol, &class) != noErr ) {
87 loaderror = "Symbol not found";
88 }
89
90 if ( symbol == NULL ) {
91 SDL_SetError("Failed loading %s: %s", name, loaderror);
92 }
93 return(symbol);
94 }
95
96 void SDL_UnloadObject(void *handle)
97 {
98 CFragConnectionID library_id;
99 if ( handle != NULL ) {
100 library_id = (CFragConnectionID)handle;
101 CloseConnection(&library_id);
102 }
103 }
104