annotate src/SDL_loadso.c @ 1162:2651158f59b8

Enable altivec blitters on PowerPC Linux, and some fixes for recent GCCs versions.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 20 Oct 2005 06:55:26 +0000
parents 51a8702d8ecd
children e9cf8c1b4590
rev   line source
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 708
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #ifdef SAVE_RCSID
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 static char rcsid =
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 "@(#) $Id$";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #endif
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 /* System dependent library loading routines */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <stdio.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 # include <dlfcn.h>
1152
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
34 #elif defined(WIN32) || defined(_WIN32_WCE)
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 # include <windows.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 # include <be/kernel/image.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 # include <string.h>
1135
cf6133247d34 Mac Classic and CodeWarrior patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
40 #define OLDP2C 1
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 # include <Strings.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 # include <CodeFragments.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 # include <Errors.h>
651
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
44 #elif defined(__MINT__) && defined(ENABLE_LDG)
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
45 # include <gem.h>
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
46 # include <ldg.h>
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #else
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 /*#error Unsupported dynamic link environment*/
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 #endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50
296
fab1ddc4d7bf Removed the API changes to preserve SDL 1.2 stability
Sam Lantinga <slouken@libsdl.org>
parents: 294
diff changeset
51 #include "SDL_types.h"
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #include "SDL_error.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 #include "SDL_loadso.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 void *SDL_LoadObject(const char *sofile)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 void *handle = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 const char *loaderror = "SDL_LoadObject() not implemented";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 #if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 handle = dlopen(sofile, RTLD_NOW);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 loaderror = (char *)dlerror();
1152
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
63 #elif defined(_WIN32_WCE)
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
64 /* * */
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
65 char errbuf[512];
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
66
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
67 wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
68 wchar_t *sofile_t = malloc((MAX_PATH+1) * sizeof(wchar_t));
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
69
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
70 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, MAX_PATH);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
71 handle = (void *)LoadLibrary(sofile_t);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
72
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
73 /* Generate an error message if all loads failed */
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
74 if ( handle == NULL ) {
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
75 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
76 FORMAT_MESSAGE_FROM_SYSTEM),
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
77 NULL, GetLastError(),
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
78 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
79 errbuf_t, SDL_TABLESIZE(errbuf), NULL);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
80 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
81 loaderror = errbuf;
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
82 }
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
83
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
84 free(sofile_t);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
85 free(errbuf_t);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
86
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 #elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 char errbuf[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 handle = (void *)LoadLibrary(sofile);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 /* Generate an error message if all loads failed */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 FORMAT_MESSAGE_FROM_SYSTEM),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 NULL, GetLastError(),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 errbuf, SDL_TABLESIZE(errbuf), NULL);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 loaderror = errbuf;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 #elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 image_id library_id;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 library_id = load_add_on(sofile);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 if ( library_id == B_ERROR ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 loaderror = "BeOS error";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 } else {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 handle = (void *)(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 #elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 CFragConnectionID library_id;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 Ptr mainAddr;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 Str255 errName;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 OSErr error;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 char psofile[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 psofile[SDL_TABLESIZE(psofile)-1] = '\0';
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 kLoadCFrag, &library_id, &mainAddr, errName);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 switch (error) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 case noErr:
774
0c3e00cc9580 Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
126 loaderror = NULL;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 case cfragNoLibraryErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 loaderror = "Library not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 case cfragUnresolvedErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 loaderror = "Unabled to resolve symbols";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 case cfragNoPrivateMemErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 case cfragNoClientMemErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 loaderror = "Out of memory";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 default:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 loaderror = "Unknown Code Fragment Manager error";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 if ( loaderror == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 handle = (void *)(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 }
651
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
145 #elif defined(__MINT__) && defined(ENABLE_LDG)
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
146 /* * */
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
147 handle = (void *)ldg_open((char *)sofile, ldg_global);
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 #endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 SDL_SetError("Failed loading %s: %s", sofile, loaderror);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 return(handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 void *SDL_LoadFunction(void *handle, const char *name)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 void *symbol = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 const char *loaderror = "SDL_LoadFunction not implemented";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 #if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 symbol = dlsym(handle, name);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 loaderror = (char *)dlerror();
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 }
1152
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
166 #elif defined(_WIN32_WCE)
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
167 /* * */
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
168 char errbuf[512];
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
169 int length = strlen(name);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
170
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
171 wchar_t *name_t = malloc((length + 1) * sizeof(wchar_t));
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
172 wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
173
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
174 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
175
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
176 symbol = (void *)GetProcAddress((HMODULE)handle, name_t);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
177 if ( symbol == NULL ) {
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
178 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
179 FORMAT_MESSAGE_FROM_SYSTEM),
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
180 NULL, GetLastError(),
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
181 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
182 errbuf_t, SDL_TABLESIZE(errbuf), NULL);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
183 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
184 loaderror = errbuf;
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
185 }
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
186
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
187 free(name_t);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
188 free(errbuf_t);
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 1135
diff changeset
189
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 #elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 char errbuf[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 symbol = (void *)GetProcAddress((HMODULE)handle, name);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 FORMAT_MESSAGE_FROM_SYSTEM),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 NULL, GetLastError(),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 errbuf, SDL_TABLESIZE(errbuf), NULL);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 loaderror = errbuf;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 #elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 image_id library_id = (image_id)handle;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 if ( get_image_symbol(library_id,
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 loaderror = "Symbol not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 #elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 CFragSymbolClass class;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 CFragConnectionID library_id = (CFragConnectionID)handle;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 char pname[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 strncpy(pname, name, SDL_TABLESIZE(pname));
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 pname[SDL_TABLESIZE(pname)-1] = '\0';
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 if ( FindSymbol(library_id, C2PStr(pname),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 (char **)&symbol, &class) != noErr ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 loaderror = "Symbol not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 }
651
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
222 #elif defined(__MINT__) && defined(ENABLE_LDG)
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
223 /* * */
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
224 symbol = (void *)ldg_find((char *)name, (LDG *)handle);
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 #endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 SDL_SetError("Failed loading %s: %s", name, loaderror);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 return(symbol);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 void SDL_UnloadObject(void *handle)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 {
336
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
235 #if defined(__BEOS__)
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
236 image_id library_id;
707
c67d4fb10a45 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 651
diff changeset
237 #elif defined(macintosh)
c67d4fb10a45 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 651
diff changeset
238 CFragConnectionID library_id;
336
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
239 #endif
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 return;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 }
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 #if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 dlclose(handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 #elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 /* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 FreeLibrary((HMODULE)handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 #elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 /* * */
336
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
251 library_id = (image_id)handle;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 unload_add_on(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 #elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 /* * */
707
c67d4fb10a45 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 651
diff changeset
255 library_id = (CFragConnectionID)handle;
708
d0d50f2b044c Fixed building SDL_loadso.c on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents: 707
diff changeset
256 CloseConnection(&library_id);
651
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
257 #elif defined(__MINT__) && defined(ENABLE_LDG)
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
258 /* * */
35ff0890ac4e pmandin: Added Atari LDG shared object loader
Patrice Mandin <patmandin@gmail.com>
parents: 336
diff changeset
259 ldg_close((LDG *)handle, ldg_global);
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 #endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 }