src/loadso/os2/SDL_loadso.c
author Sam Lantinga
Wed, 01 Feb 2006 06:32:25 +0000
changeset 1312 c9b51268668f
parent 1190 173c063d4f55
child 1358 c71e05b4dc2e
permissions -rw-r--r--
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
icculus@1190
     1
/*
icculus@1190
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
icculus@1190
     4
icculus@1190
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
icculus@1190
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 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
slouken@1312
    13
    Lesser General Public License for more details.
icculus@1190
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
icculus@1190
    18
icculus@1190
    19
    Sam Lantinga
icculus@1190
    20
    slouken@libsdl.org
icculus@1190
    21
*/
icculus@1190
    22
icculus@1190
    23
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
icculus@1190
    24
/* System dependent library loading routines                           */
icculus@1190
    25
icculus@1190
    26
#if !SDL_INTERNAL_BUILDING_LOADSO
icculus@1190
    27
#error Do not compile directly...compile src/SDL_loadso.c instead!
icculus@1190
    28
#endif
icculus@1190
    29
icculus@1190
    30
#if !defined(__OS2__)
icculus@1190
    31
#error Compiling for the wrong platform?
icculus@1190
    32
#endif
icculus@1190
    33
icculus@1190
    34
#include <stdio.h>
icculus@1190
    35
#define INCL_DOSERRORS
icculus@1190
    36
#define INCL_DOSMODULEMGR
icculus@1190
    37
#include <os2.h>
icculus@1190
    38
icculus@1190
    39
#include "SDL_types.h"
icculus@1190
    40
#include "SDL_error.h"
icculus@1190
    41
#include "SDL_loadso.h"
icculus@1190
    42
icculus@1190
    43
void *SDL_LoadObject(const char *sofile)
icculus@1190
    44
{
icculus@1190
    45
    HMODULE handle = NULL;
icculus@1190
    46
    char buf[512];
icculus@1190
    47
    APIRET ulrc = DosLoadModule(buf, sizeof (buf), (char *) sofile, &handle);
icculus@1190
    48
icculus@1190
    49
    /* Generate an error message if all loads failed */
icculus@1190
    50
    if ((ulrc != NO_ERROR) || (handle == NULL))
icculus@1190
    51
        SDL_SetError("Failed loading %s: %s", sofile, buf);
icculus@1190
    52
icculus@1190
    53
    return((void *) handle);
icculus@1190
    54
}
icculus@1190
    55
icculus@1190
    56
void *SDL_LoadFunction(void *handle, const char *name)
icculus@1190
    57
{
icculus@1190
    58
    const char *loaderror = "Unknown error";
icculus@1190
    59
    void *symbol = NULL;
icculus@1190
    60
    APIRET ulrc = DosQueryProcAddr((HMODULE)handle, 0, (char *)name, &symbol);
icculus@1190
    61
    if (ulrc == ERROR_INVALID_HANDLE)
icculus@1190
    62
        loaderror = "Invalid module handle";
icculus@1190
    63
    else if (ulrc == ERROR_INVALID_NAME)
icculus@1190
    64
        loaderror = "Symbol not found";
icculus@1190
    65
icculus@1190
    66
    if (symbol == NULL)
icculus@1190
    67
        SDL_SetError("Failed loading %s: %s", name, loaderror);
icculus@1190
    68
icculus@1190
    69
    return(symbol);
icculus@1190
    70
}
icculus@1190
    71
icculus@1190
    72
void SDL_UnloadObject(void *handle)
icculus@1190
    73
{
icculus@1190
    74
    if ( handle != NULL )
icculus@1190
    75
        DosFreeModule((HMODULE) handle);
icculus@1190
    76
}
icculus@1190
    77