Commit d8ec9e79 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Split up src/SDL_loadso.c into platform directories.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401176
parent 3c37bc53
......@@ -304,11 +304,11 @@ CheckALSA()
alsa_lib=`ls $alsa_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
echo "-- $alsa_lib_spec -> $alsa_lib"
if test x$use_dlopen != xyes && \
if test x$have_loadso != xyes && \
test x$enable_alsa_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
AC_MSG_ERROR([You must have SDL_LoadObject() support])
fi
if test x$use_dlopen = xyes && \
if test x$have_loadso = xyes && \
test x$enable_alsa_shared = xyes && test x$alsa_lib != x; then
CFLAGS="$CFLAGS -DALSA_SUPPORT -DALSA_DYNAMIC=\$(alsa_lib) $ALSA_CFLAGS"
AC_SUBST(alsa_lib)
......@@ -367,11 +367,11 @@ CheckESD()
esd_lib_spec=`echo $ESD_LIBS | sed 's/.*-L\([[^ ]]*\).*/\1\/libesd.so.*/'`
esd_lib=`ls $esd_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
echo "-- $esd_lib_spec -> $esd_lib"
if test x$use_dlopen != xyes && \
if test x$have_loadso != xyes && \
test x$enable_esd_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
AC_MSG_ERROR([You must have SDL_LoadObject() support])
fi
if test x$use_dlopen = xyes && \
if test x$have_loadso = xyes && \
test x$enable_esd_shared = xyes && test x$esd_lib != x; then
CFLAGS="$CFLAGS -DESD_SUPPORT -DESD_DYNAMIC=\$(esd_lib) $ESD_CFLAGS"
AC_SUBST(esd_lib)
......@@ -418,11 +418,11 @@ CheckARTSC()
arts_lib_spec="$ARTSC_PREFIX/lib/libartsc.so.*"
arts_lib=`ls $arts_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
echo "-- $arts_lib_spec -> $arts_lib"
if test x$use_dlopen != xyes && \
if test x$have_loadso != xyes && \
test x$enable_arts_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
AC_MSG_ERROR([You must have SDL_LoadObject() support])
fi
if test x$use_dlopen = xyes && \
if test x$have_loadso = xyes && \
test x$enable_arts_shared = xyes && test x$arts_lib != x; then
CFLAGS="$CFLAGS -DARTSC_SUPPORT -DARTSC_DYNAMIC=\$(arts_lib) $ARTSC_CFLAGS"
AC_SUBST(arts_lib)
......@@ -617,12 +617,12 @@ CheckX11()
x11_lib='libX11.so.6'
x11ext_lib='libXext.so.6'
if test x$use_dlopen != xyes && \
if test x$have_loadso != xyes && \
test x$enable_x11_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
AC_MSG_ERROR([You must have SDL_LoadObject() support])
fi
if test x$use_dlopen = xyes && \
if test x$have_loadso = xyes && \
test x$enable_x11_shared = xyes && test x$x11_lib != x && test x$x11ext_lib != x; then
CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -DX11_DYNAMIC=\$(x11_lib) -DX11EXT_DYNAMIC=\$(x11ext_lib) -I$srcdir/include -I$srcdir/src/video"
SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS"
......@@ -1131,7 +1131,7 @@ CheckOpenGL()
AC_MSG_RESULT($video_opengl)
if test x$video_opengl = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGL"
if test x$use_dlopen != xyes; then
if test x$have_loadso != xyes; then
AC_CHECK_LIB(dl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -ldl")
fi
fi
......@@ -1154,7 +1154,7 @@ CheckOpenGLQNX()
if test x$video_opengl = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGL"
SYSTEM_LIBS="$SYSTEM_LIBS -lGL"
if test x$use_dlopen != xyes; then
if test x$have_loadso != xyes; then
AC_CHECK_LIB(c, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS", AC_CHECK_LIB(ltdl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -lltdl"))
fi
fi
......@@ -1778,16 +1778,16 @@ CheckDLOPEN()
, enable_sdl_dlopen=yes)
if test x$enable_sdl_dlopen = xyes; then
AC_MSG_CHECKING(for dlopen)
use_dlopen=no
have_loadso=no
AC_TRY_COMPILE([
#include <dlfcn.h>
],[
],[
use_dlopen=yes
have_loadso=yes
])
AC_MSG_RESULT($use_dlopen)
AC_MSG_RESULT($have_loadso)
if test x$use_dlopen = xyes; then
if test x$have_loadso = xyes; then
CFLAGS="$CFLAGS -DUSE_DLOPEN"
AC_CHECK_LIB(c, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS",
AC_CHECK_LIB(dl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -ldl",
......@@ -1806,6 +1806,7 @@ CheckAtariLdg()
AC_CHECK_HEADER(ldg.h, have_ldg_hdr=yes)
AC_CHECK_LIB(ldg, ldg_open, have_ldg_lib=yes, have_ldg_lib=no, -lgem)
if test x$have_ldg_hdr = xyes -a x$have_ldg_lib = xyes; then
have_loadso=yes
CFLAGS="$CFLAGS -DENABLE_LDG"
SYSTEM_LIBS="$SYSTEM_LIBS -lldg -lgem"
fi
......@@ -1989,6 +1990,7 @@ CheckRPATH()
, enable_rpath=yes)
}
have_loadso=no
case "$target" in
arm-*-elf*)
ARCH=linux
......@@ -2560,6 +2562,7 @@ case "$target" in
;;
*-*-cygwin* | *-*-mingw32*)
ARCH=win32
have_loadso=yes
if test "$build" != "$target"; then # cross-compiling
# Default cross-compile location
ac_default_prefix=/usr/local/cross-tools/i386-mingw32msvc
......@@ -2625,6 +2628,7 @@ case "$target" in
*-*-beos*)
ARCH=beos
ac_default_prefix=/boot/develop/tools/gnupro
have_loadso=yes
CheckDummyVideo
CheckDiskAudio
CheckNASM
......@@ -2668,6 +2672,7 @@ case "$target" in
# use it at present, but Apple is working on a X-to-9 compiler
# for which this case would be handy.
ARCH=macos
have_loadso=yes
CheckDummyVideo
CheckDiskAudio
CheckTOOLBOX
......@@ -2711,6 +2716,7 @@ case "$target" in
# just the OS X kernel sans upper layers like Carbon and Cocoa.
# Next line is broken, and a few files below require Mac OS X (full)
ARCH=macosx
have_loadso=yes
CheckDummyVideo
CheckDiskAudio
CheckCOCOA
......
......@@ -28,234 +28,23 @@ static char rcsid =
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */
#include <stdio.h>
#if defined(USE_DLOPEN)
# include <dlfcn.h>
/* !!! FIXME: includes so I don't have to update all the project files... */
#define SDL_INTERNAL_BUILDING_LOADSO 1
#if defined(USE_DUMMY_LOADSO)
# include "loadso/dummy/SDL_loadso.c"
#elif defined(MACOSX)
# include "loadso/macosx/SDL_loadso.c"
#elif defined(macintosh)
# include "loadso/macos/SDL_loadso.c"
#elif defined(USE_DLOPEN)
# include "loadso/dlopen/SDL_loadso.c"
#elif defined(WIN32) || defined(_WIN32_WCE)
# include <windows.h>
# include "loadso/windows/SDL_loadso.c"
#elif defined(__BEOS__)
# include <be/kernel/image.h>
#elif defined(macintosh)
# include <string.h>
#define OLDP2C 1
# include <Strings.h>
# include <CodeFragments.h>
# include <Errors.h>
# include "loadso/beos/SDL_loadso.c"
#elif defined(__MINT__) && defined(ENABLE_LDG)
# include <gem.h>
# include <ldg.h>
# include "loadso/mint/SDL_loadso.c"
#else
/*#error Unsupported dynamic link environment*/
# include "loadso/dummy/SDL_loadso.c"
#endif /* system type */
#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_loadso.h"
void *SDL_LoadObject(const char *sofile)
{
void *handle = NULL;
const char *loaderror = "SDL_LoadObject() not implemented";
#if defined(USE_DLOPEN)
/* * */
handle = dlopen(sofile, RTLD_NOW);
loaderror = (char *)dlerror();
#elif defined(_WIN32_WCE)
/* * */
char errbuf[512];
wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
wchar_t *sofile_t = malloc((MAX_PATH+1) * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, MAX_PATH);
handle = (void *)LoadLibrary(sofile_t);
/* Generate an error message if all loads failed */
if ( handle == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf_t, SDL_TABLESIZE(errbuf), NULL);
WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
loaderror = errbuf;
}
free(sofile_t);
free(errbuf_t);
#elif defined(WIN32)
/* * */
char errbuf[512];
handle = (void *)LoadLibrary(sofile);
/* Generate an error message if all loads failed */
if ( handle == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf, SDL_TABLESIZE(errbuf), NULL);
loaderror = errbuf;
}
#elif defined(__BEOS__)
/* * */
image_id library_id;
library_id = load_add_on(sofile);
if ( library_id == B_ERROR ) {
loaderror = "BeOS error";
} else {
handle = (void *)(library_id);
}
#elif defined(macintosh)
/* * */
CFragConnectionID library_id;
Ptr mainAddr;
Str255 errName;
OSErr error;
char psofile[512];
strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
psofile[SDL_TABLESIZE(psofile)-1] = '\0';
error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
kLoadCFrag, &library_id, &mainAddr, errName);
switch (error) {
case noErr:
loaderror = NULL;
break;
case cfragNoLibraryErr:
loaderror = "Library not found";
break;
case cfragUnresolvedErr:
loaderror = "Unabled to resolve symbols";
break;
case cfragNoPrivateMemErr:
case cfragNoClientMemErr:
loaderror = "Out of memory";
break;
default:
loaderror = "Unknown Code Fragment Manager error";
break;
}
if ( loaderror == NULL ) {
handle = (void *)(library_id);
}
#elif defined(__MINT__) && defined(ENABLE_LDG)
/* * */
handle = (void *)ldg_open((char *)sofile, ldg_global);
#endif /* system type */
if ( handle == NULL ) {
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
}
return(handle);
}
void *SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = NULL;
const char *loaderror = "SDL_LoadFunction not implemented";
#if defined(USE_DLOPEN)
/* * */
symbol = dlsym(handle, name);
if ( symbol == NULL ) {
loaderror = (char *)dlerror();
}
#elif defined(_WIN32_WCE)
/* * */
char errbuf[512];
int length = strlen(name);
wchar_t *name_t = malloc((length + 1) * sizeof(wchar_t));
wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length);
symbol = (void *)GetProcAddress((HMODULE)handle, name_t);
if ( symbol == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf_t, SDL_TABLESIZE(errbuf), NULL);
WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
loaderror = errbuf;
}
free(name_t);
free(errbuf_t);
#elif defined(WIN32)
/* * */
char errbuf[512];
symbol = (void *)GetProcAddress((HMODULE)handle, name);
if ( symbol == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf, SDL_TABLESIZE(errbuf), NULL);
loaderror = errbuf;
}
#elif defined(__BEOS__)
/* * */
image_id library_id = (image_id)handle;
if ( get_image_symbol(library_id,
name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR ) {
loaderror = "Symbol not found";
}
#elif defined(macintosh)
/* * */
CFragSymbolClass class;
CFragConnectionID library_id = (CFragConnectionID)handle;
char pname[512];
strncpy(pname, name, SDL_TABLESIZE(pname));
pname[SDL_TABLESIZE(pname)-1] = '\0';
if ( FindSymbol(library_id, C2PStr(pname),
(char **)&symbol, &class) != noErr ) {
loaderror = "Symbol not found";
}
#elif defined(__MINT__) && defined(ENABLE_LDG)
/* * */
symbol = (void *)ldg_find((char *)name, (LDG *)handle);
#endif /* system type */
if ( symbol == NULL ) {
SDL_SetError("Failed loading %s: %s", name, loaderror);
}
return(symbol);
}
void SDL_UnloadObject(void *handle)
{
#if defined(__BEOS__)
image_id library_id;
#elif defined(macintosh)
CFragConnectionID library_id;
#endif
if ( handle == NULL ) {
return;
}
#if defined(USE_DLOPEN)
/* * */
dlclose(handle);
#elif defined(WIN32)
/* * */
FreeLibrary((HMODULE)handle);
#elif defined(__BEOS__)
/* * */
library_id = (image_id)handle;
unload_add_on(library_id);
#elif defined(macintosh)
/* * */
library_id = (CFragConnectionID)handle;
CloseConnection(&library_id);
#elif defined(__MINT__) && defined(ENABLE_LDG)
/* * */
ldg_close((LDG *)handle, ldg_global);
#endif /* system type */
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */
#if !SDL_INTERNAL_BUILDING_LOADSO
#error Do not compile directly...compile src/SDL_loadso.c instead!
#endif
#if !defined(__BEOS__)
#error Compiling for the wrong platform?
#endif
#include <stdio.h>
#include <be/kernel/image.h>
#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_loadso.h"
void *SDL_LoadObject(const char *sofile)
{
void *handle = NULL;
const char *loaderror = "Unknown error";
image_id library_id = load_add_on(sofile);
if ( library_id == B_ERROR ) {
loaderror = "BeOS error";
} else {
handle = (void *)(library_id);
}
if ( handle == NULL ) {
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
}
return(handle);
}
void *SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = NULL;
const char *loaderror = "Unknown error";
image_id library_id = (image_id)handle;
if ( get_image_symbol(library_id,
name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR ) {
loaderror = "Symbol not found";
}
if ( symbol == NULL ) {
SDL_SetError("Failed loading %s: %s", name, loaderror);
}
return(symbol);
}
void SDL_UnloadObject(void *handle)
{
image_id library_id;
if ( handle != NULL ) {
library_id = (image_id)handle;
unload_add_on(library_id);
}
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */
#if !SDL_INTERNAL_BUILDING_LOADSO
#error Do not compile directly...compile src/SDL_loadso.c instead!
#endif
#if !defined(USE_DLOPEN)
#error Compiling for the wrong platform?
#endif
#include <stdio.h>
#include <dlfcn.h>
#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_loadso.h"
void *SDL_LoadObject(const char *sofile)
{
void *handle = dlopen(sofile, RTLD_NOW);
const char *loaderror = (char *)dlerror();
if ( handle == NULL ) {
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
}
return(handle);
}
void *SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = dlsym(handle, name);
if ( symbol == NULL ) {
SDL_SetError("Failed loading %s: %s", name, (const char *)dlerror());
}
return(symbol);
}
void SDL_UnloadObject(void *handle)
{
if ( handle != NULL ) {
dlclose(handle);
}
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */
#if !SDL_INTERNAL_BUILDING_LOADSO
#error Do not compile directly...compile src/SDL_loadso.c instead!
#endif
#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_loadso.h"
void *SDL_LoadObject(const char *sofile)
{
const char *loaderror = "SDL_LoadObject() not implemented";
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
return(NULL);
}
void *SDL_LoadFunction(void *handle, const char *name)
{
const char *loaderror = "SDL_LoadFunction not implemented";
SDL_SetError("Failed loading %s: %s", name, loaderror);
return(NULL);
}
void SDL_UnloadObject(void *handle)
{
/* no-op. */
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */
#if !SDL_INTERNAL_BUILDING_LOADSO
#error Do not compile directly...compile src/SDL_loadso.c instead!
#endif
#if !defined(macintosh)
#error Compiling for the wrong platform?
#endif
#include <stdio.h>
#include <string.h>
#define OLDP2C 1
#include <Strings.h>
#include <CodeFragments.h>
#include <Errors.h>
#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_loadso.h"
void *SDL_LoadObject(const char *sofile)
{
void *handle = NULL;
const char *loaderror = NULL;
CFragConnectionID library_id;
Ptr mainAddr;
Str255 errName;
OSErr error;
char psofile[512];
strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
psofile[SDL_TABLESIZE(psofile)-1] = '\0';
error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
kLoadCFrag, &library_id, &mainAddr, errName);
switch (error) {
case noErr:
loaderror = NULL;
break;
case cfragNoLibraryErr:
loaderror = "Library not found";
break;
case cfragUnresolvedErr:
loaderror = "Unabled to resolve symbols";
break;
case cfragNoPrivateMemErr:
case cfragNoClientMemErr:
loaderror = "Out of memory";
break;
default:
loaderror = "Unknown Code Fragment Manager error";
break;
}
if ( loaderror == NULL ) {
handle = (void *)(library_id);
} else {
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
}
return(handle);
}
void *SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = NULL;
const char *loaderror = NULL;
CFragSymbolClass class;
CFragConnectionID library_id = (CFragConnectionID)handle;
char pname[512];
strncpy(pname, name, SDL_TABLESIZE(pname));
pname[SDL_TABLESIZE(pname)-1] = '\0';
if ( FindSymbol(library_id, C2PStr(pname),
(char **)&symbol, &class) != noErr ) {
loaderror = "Symbol not found";
}
if ( symbol == NULL ) {
SDL_SetError("Failed loading %s: %s", name, loaderror);
}
return(symbol);
}
void SDL_UnloadObject(void *handle)
{
CFragConnectionID library_id;
if ( handle != NULL ) {
library_id = (CFragConnectionID)handle;
CloseConnection(&library_id);
}
}
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */
#if !SDL_INTERNAL_BUILDING_LOADSO
#error Do not compile directly...compile src/SDL_loadso.c instead!
#endif
/* please use the "dummy" driver if you don't have LDG support enabled. */
#if !defined(__MINT__) || !defined(ENABLE_LDG)
#error Compiling for the wrong platform?
#endif
#include <stdio.h>
#include <gem.h>
#include <ldg.h>
#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_loadso.h"
void *SDL_LoadObject(const char *sofile)
{
const char *loaderror = "Unknown error";
void *handle = (void *)ldg_open((char *)sofile, ldg_global);
if ( handle == NULL ) {
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
}
return(handle);
}
void *SDL_LoadFunction(void *handle, const char *name)
{
const char *loaderror = "Unknown error";
void *symbol = (void *)ldg_find((char *)name, (LDG *)handle);
if ( symbol == NULL ) {
SDL_SetError("Failed loading %s: %s", name, loaderror);
}
return(symbol);
}
void SDL_UnloadObject(void *handle)
{
if ( handle != NULL ) {
ldg_close((LDG *)handle, ldg_global);
}
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */
#if !SDL_INTERNAL_BUILDING_LOADSO
#error Do not compile directly...compile src/SDL_loadso.c instead!
#endif
#if !defined(WIN32) && !defined(_WIN32_WCE)
#error Compiling for the wrong platform?
#endif
#include <stdio.h>
#include <windows.h>
#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_loadso.h"
void *SDL_LoadObject(const char *sofile)
{
void *handle = NULL;
const char *loaderror = "Unknown error";
#if defined(_WIN32_WCE)
char errbuf[512];
wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
wchar_t *sofile_t = malloc((MAX_PATH+1) * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, MAX_PATH);
handle = (void *)LoadLibrary(sofile_t);
/* Generate an error message if all loads failed */
if ( handle == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf_t, SDL_TABLESIZE(errbuf), NULL);
WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
loaderror = errbuf;
}
free(sofile_t);
free(errbuf_t);
#else /*if defined(WIN32)*/
char errbuf[512];
handle = (void *)LoadLibrary(sofile);
/* Generate an error message if all loads failed */
if ( handle == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf, SDL_TABLESIZE(errbuf), NULL);
loaderror = errbuf;
}
#endif
if ( handle == NULL ) {
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
}
return(handle);
}
void *SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = NULL;
const char *loaderror = "Unknown error";
#if defined(_WIN32_WCE)
char errbuf[512];
int length = strlen(name);
wchar_t *name_t = malloc((length + 1) * sizeof(wchar_t));
wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length);
symbol = (void *)GetProcAddress((HMODULE)handle, name_t);
if ( symbol == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf_t, SDL_TABLESIZE(errbuf), NULL);
WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
loaderror = errbuf;
}
free(name_t);
free(errbuf_t);
#else /*if defined(WIN32)*/
char errbuf[512];
symbol = (void *)GetProcAddress((HMODULE)handle, name);
if ( symbol == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf, SDL_TABLESIZE(errbuf), NULL);
loaderror = errbuf;
}
#endif
if ( symbol == NULL ) {
SDL_SetError("Failed loading %s: %s", name, loaderror);
}
return(symbol);
}
void SDL_UnloadObject(void *handle)
{
if ( handle != NULL ) {
FreeLibrary((HMODULE)handle);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment