src/SDL_loadso.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 10 Apr 2002 17:12:32 +0000
changeset 336 745873ea091f
parent 297 f6ffac90895c
child 651 35ff0890ac4e
permissions -rw-r--r--
BeOS compile fix for shared object loading code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
297
f6ffac90895c Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents: 296
diff changeset
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  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>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#elif defined(WIN32)
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>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
# include <Strings.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
# include <CodeFragments.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
# include <Errors.h>
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
#else
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
/*#error Unsupported dynamic link environment*/
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
#endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
296
fab1ddc4d7bf Removed the API changes to preserve SDL 1.2 stability
Sam Lantinga <slouken@libsdl.org>
parents: 294
diff changeset
    47
#include "SDL_types.h"
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
#include "SDL_error.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
#include "SDL_loadso.h"
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
void *SDL_LoadObject(const char *sofile)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
{
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
	void *handle = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
	const char *loaderror = "SDL_LoadObject() not implemented";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
#if defined(USE_DLOPEN)
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
	handle = dlopen(sofile, RTLD_NOW);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
	loaderror = (char *)dlerror();
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
#elif defined(WIN32)
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
	char errbuf[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
	handle = (void *)LoadLibrary(sofile);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
	/* 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
    66
	if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
		FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
					FORMAT_MESSAGE_FROM_SYSTEM),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
				NULL, GetLastError(), 
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
				errbuf, SDL_TABLESIZE(errbuf), NULL);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
		loaderror = errbuf;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
#elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
/* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
	image_id library_id;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
	library_id = load_add_on(sofile);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
	if ( library_id == B_ERROR ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
		loaderror = "BeOS error";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
	} else {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
		handle = (void *)(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
#elif defined(macintosh)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
/* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
	CFragConnectionID library_id;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
	Ptr mainAddr;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
	Str255 errName;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
	OSErr error;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
	char psofile[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
	strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
	psofile[SDL_TABLESIZE(psofile)-1] = '\0';
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
	error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
			kLoadCFrag, &library_id, &mainAddr, errName);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
	switch (error) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
		case noErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
			break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
		case cfragNoLibraryErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
			loaderror = "Library not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
			break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
		case cfragUnresolvedErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
			loaderror = "Unabled to resolve symbols";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
			break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
		case cfragNoPrivateMemErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
		case cfragNoClientMemErr:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
			loaderror = "Out of memory";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
			break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
		default:
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
			loaderror = "Unknown Code Fragment Manager error";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
			break;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
	if ( loaderror == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
		handle = (void *)(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
#endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
	if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
		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
   120
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
	return(handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
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
   125
{
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
	void *symbol = NULL;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
	const char *loaderror = "SDL_LoadFunction not implemented";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
#if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
/* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
	symbol = dlsym(handle, name);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
	if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
		loaderror = (char *)dlerror();
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
#elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
/* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
	char errbuf[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
	symbol = (void *)GetProcAddress((HMODULE)handle, name);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
	if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
		FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
					FORMAT_MESSAGE_FROM_SYSTEM),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
				NULL, GetLastError(), 
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
				errbuf, SDL_TABLESIZE(errbuf), NULL);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
		loaderror = errbuf;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
#elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
/* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
	image_id library_id = (image_id)handle;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
	if ( get_image_symbol(library_id,
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
		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
   152
		loaderror = "Symbol not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
#elif defined(macintosh)
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
	CFragSymbolClass class;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
	CFragConnectionID library_id = (CFragConnectionID)handle;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
	char pname[512];
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
	strncpy(pname, name, SDL_TABLESIZE(pname));
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
	pname[SDL_TABLESIZE(pname)-1] = '\0';
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
	if ( FindSymbol(library_id, C2PStr(pname),
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
	                (char **)&symbol, &class) != noErr ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
		loaderror = "Symbol not found";
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
#endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
	if ( symbol == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
		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
   170
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
	return(symbol);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
void SDL_UnloadObject(void *handle)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
{
336
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   176
#if defined(__BEOS__)
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   177
	image_id library_id;
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   178
#endif
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
	if ( handle == NULL ) {
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
		return;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
	}
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
#if defined(USE_DLOPEN)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
/* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
	dlclose(handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
#elif defined(WIN32)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
/* * */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
	FreeLibrary((HMODULE)handle);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
#elif defined(__BEOS__)
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
/* * */
336
745873ea091f BeOS compile fix for shared object loading code
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   190
	library_id = (image_id)handle;
294
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
	unload_add_on(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
#elif defined(macintosh)
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
	CFragConnectionID library_id = (CFragConnectionID)handle;
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
	CloseConnection(library_id);
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
#endif /* system type */
d2d48e10f370 Added a new header file: SDL_loadso.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
}