dl_posix.c 1.88 KB
Newer Older
1 2
/*
 * This file is part of libbluray
3
 * Copyright (C) 2009-2010  Obliter0n
4 5
 * Copyright (C) 2009-2010  John Stebbins
 *
gates's avatar
gates committed
6 7 8 9
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
10
 *
gates's avatar
gates committed
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
gates's avatar
gates committed
13 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
15
 *
gates's avatar
gates committed
16 17 18
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
19 20
 */

21 22 23 24
#if HAVE_CONFIG_H
#include "config.h"
#endif

25 26 27
#include "dl.h"
#include "util/macro.h"
#include "util/logging.h"
28
#include "util/strutl.h"
29

30 31
#include <stdlib.h>
#include <dlfcn.h>
32
#include <string.h>
33

34
void   *dl_dlopen  ( const char* path, const char *version )
35
{
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    char *name;
    void *result;

#if defined(__APPLE__)
    static const char ext[] = ".dylib";
    version = NULL;
#else
    static const char ext[] = ".so";
#endif

    if (version) {
        name = str_printf("%s%s.%s", path, ext, version);
    } else {
        name = str_printf("%s%s", path, ext);
    }

    DEBUG(DBG_BDPLUS, "searching for library '%s' ...\n", name);

    result = dlopen(name, RTLD_LAZY);
hpi1's avatar
hpi1 committed
55
    if (!result) {
56
        DEBUG(DBG_FILE, "can't open library '%s': %s\n", name, dlerror());
hpi1's avatar
hpi1 committed
57
    }
58 59 60

    X_FREE(name);

61 62 63 64 65
    return result;
}

void   *dl_dlsym   ( void* handle, const char* symbol )
{
hpi1's avatar
hpi1 committed
66 67 68
    void *result = dlsym(handle, symbol);

    if (!result) {
69
        DEBUG(DBG_FILE | DBG_CRIT, "dlsym(%p, '%s') failed: %s\n", handle, symbol, dlerror());
hpi1's avatar
hpi1 committed
70 71 72
    }

    return result;
73 74 75 76 77 78
}

int     dl_dlclose ( void* handle )
{
    return dlclose(handle);
}