src/loadso/os2/SDL_loadso.c
author Ryan C. Gordon
Wed, 23 Nov 2005 07:29:56 +0000
changeset 1190 173c063d4f55
child 1312 c9b51268668f
permissions -rw-r--r--
OS/2 port!

This was mostly, if not entirely, written by "Doodle" and "Caetano":
doodle@scenergy.dfmk.hu
daniel@caetano.eng.br

--ryan.
icculus@1190
     1
/*
icculus@1190
     2
    SDL - Simple DirectMedia Layer
icculus@1190
     3
    Copyright (C) 1997-2004 Sam Lantinga
icculus@1190
     4
icculus@1190
     5
    This library is free software; you can redistribute it and/or
icculus@1190
     6
    modify it under the terms of the GNU Library General Public
icculus@1190
     7
    License as published by the Free Software Foundation; either
icculus@1190
     8
    version 2 of the License, or (at your option) any later version.
icculus@1190
     9
icculus@1190
    10
    This library is distributed in the hope that it will be useful,
icculus@1190
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
icculus@1190
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
icculus@1190
    13
    Library General Public License for more details.
icculus@1190
    14
icculus@1190
    15
    You should have received a copy of the GNU Library General Public
icculus@1190
    16
    License along with this library; if not, write to the Free
icculus@1190
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
icculus@1190
    18
icculus@1190
    19
    Sam Lantinga
icculus@1190
    20
    slouken@libsdl.org
icculus@1190
    21
*/
icculus@1190
    22
icculus@1190
    23
#ifdef SAVE_RCSID
icculus@1190
    24
static char rcsid =
icculus@1190
    25
 "@(#) $Id$";
icculus@1190
    26
#endif
icculus@1190
    27
icculus@1190
    28
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
icculus@1190
    29
/* System dependent library loading routines                           */
icculus@1190
    30
icculus@1190
    31
#if !SDL_INTERNAL_BUILDING_LOADSO
icculus@1190
    32
#error Do not compile directly...compile src/SDL_loadso.c instead!
icculus@1190
    33
#endif
icculus@1190
    34
icculus@1190
    35
#if !defined(__OS2__)
icculus@1190
    36
#error Compiling for the wrong platform?
icculus@1190
    37
#endif
icculus@1190
    38
icculus@1190
    39
#include <stdio.h>
icculus@1190
    40
#define INCL_DOSERRORS
icculus@1190
    41
#define INCL_DOSMODULEMGR
icculus@1190
    42
#include <os2.h>
icculus@1190
    43
icculus@1190
    44
#include "SDL_types.h"
icculus@1190
    45
#include "SDL_error.h"
icculus@1190
    46
#include "SDL_loadso.h"
icculus@1190
    47
icculus@1190
    48
void *SDL_LoadObject(const char *sofile)
icculus@1190
    49
{
icculus@1190
    50
    HMODULE handle = NULL;
icculus@1190
    51
    char buf[512];
icculus@1190
    52
    APIRET ulrc = DosLoadModule(buf, sizeof (buf), (char *) sofile, &handle);
icculus@1190
    53
icculus@1190
    54
    /* Generate an error message if all loads failed */
icculus@1190
    55
    if ((ulrc != NO_ERROR) || (handle == NULL))
icculus@1190
    56
        SDL_SetError("Failed loading %s: %s", sofile, buf);
icculus@1190
    57
icculus@1190
    58
    return((void *) handle);
icculus@1190
    59
}
icculus@1190
    60
icculus@1190
    61
void *SDL_LoadFunction(void *handle, const char *name)
icculus@1190
    62
{
icculus@1190
    63
    const char *loaderror = "Unknown error";
icculus@1190
    64
    void *symbol = NULL;
icculus@1190
    65
    APIRET ulrc = DosQueryProcAddr((HMODULE)handle, 0, (char *)name, &symbol);
icculus@1190
    66
    if (ulrc == ERROR_INVALID_HANDLE)
icculus@1190
    67
        loaderror = "Invalid module handle";
icculus@1190
    68
    else if (ulrc == ERROR_INVALID_NAME)
icculus@1190
    69
        loaderror = "Symbol not found";
icculus@1190
    70
icculus@1190
    71
    if (symbol == NULL)
icculus@1190
    72
        SDL_SetError("Failed loading %s: %s", name, loaderror);
icculus@1190
    73
icculus@1190
    74
    return(symbol);
icculus@1190
    75
}
icculus@1190
    76
icculus@1190
    77
void SDL_UnloadObject(void *handle)
icculus@1190
    78
{
icculus@1190
    79
    if ( handle != NULL )
icculus@1190
    80
        DosFreeModule((HMODULE) handle);
icculus@1190
    81
}
icculus@1190
    82