comparison src/loadso/macos/SDL_loadso.c @ 1173:e9cf8c1b4590

Split up src/SDL_loadso.c into platform directories.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 17 Nov 2005 03:15:05 +0000
parents
children c9b51268668f
comparison
equal deleted inserted replaced
1172:f69f4d25fb20 1173:e9cf8c1b4590
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2004 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
27
28 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
29 /* System dependent library loading routines */
30
31 #if !SDL_INTERNAL_BUILDING_LOADSO
32 #error Do not compile directly...compile src/SDL_loadso.c instead!
33 #endif
34
35 #if !defined(macintosh)
36 #error Compiling for the wrong platform?
37 #endif
38
39 #include <stdio.h>
40 #include <string.h>
41 #define OLDP2C 1
42 #include <Strings.h>
43 #include <CodeFragments.h>
44 #include <Errors.h>
45
46 #include "SDL_types.h"
47 #include "SDL_error.h"
48 #include "SDL_loadso.h"
49
50 void *SDL_LoadObject(const char *sofile)
51 {
52 void *handle = NULL;
53 const char *loaderror = NULL;
54 CFragConnectionID library_id;
55 Ptr mainAddr;
56 Str255 errName;
57 OSErr error;
58 char psofile[512];
59
60 strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
61 psofile[SDL_TABLESIZE(psofile)-1] = '\0';
62 error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
63 kLoadCFrag, &library_id, &mainAddr, errName);
64 switch (error) {
65 case noErr:
66 loaderror = NULL;
67 break;
68 case cfragNoLibraryErr:
69 loaderror = "Library not found";
70 break;
71 case cfragUnresolvedErr:
72 loaderror = "Unabled to resolve symbols";
73 break;
74 case cfragNoPrivateMemErr:
75 case cfragNoClientMemErr:
76 loaderror = "Out of memory";
77 break;
78 default:
79 loaderror = "Unknown Code Fragment Manager error";
80 break;
81 }
82 if ( loaderror == NULL ) {
83 handle = (void *)(library_id);
84 } else {
85 SDL_SetError("Failed loading %s: %s", sofile, loaderror);
86 }
87 return(handle);
88 }
89
90 void *SDL_LoadFunction(void *handle, const char *name)
91 {
92 void *symbol = NULL;
93 const char *loaderror = NULL;
94 CFragSymbolClass class;
95 CFragConnectionID library_id = (CFragConnectionID)handle;
96 char pname[512];
97
98 strncpy(pname, name, SDL_TABLESIZE(pname));
99 pname[SDL_TABLESIZE(pname)-1] = '\0';
100 if ( FindSymbol(library_id, C2PStr(pname),
101 (char **)&symbol, &class) != noErr ) {
102 loaderror = "Symbol not found";
103 }
104
105 if ( symbol == NULL ) {
106 SDL_SetError("Failed loading %s: %s", name, loaderror);
107 }
108 return(symbol);
109 }
110
111 void SDL_UnloadObject(void *handle)
112 {
113 CFragConnectionID library_id;
114 if ( handle != NULL ) {
115 library_id = (CFragConnectionID)handle;
116 CloseConnection(&library_id);
117 }
118 }
119