Subversion Repositories Kolibri OS

Rev

Rev 4358 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4358 Rev 5080
1
/**************************************************************************
1
/**************************************************************************
2
 *
2
 *
3
 * Copyright 2009 VMware, Inc.
3
 * Copyright 2009 VMware, Inc.
4
 * Copyright 1999-2008  Brian Paul
4
 * Copyright 1999-2008  Brian Paul
5
 * All Rights Reserved.
5
 * All Rights Reserved.
6
 *
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 * copy of this software and associated documentation files (the
8
 * copy of this software and associated documentation files (the
9
 * "Software"), to deal in the Software without restriction, including
9
 * "Software"), to deal in the Software without restriction, including
10
 * without limitation the rights to use, copy, modify, merge, publish,
10
 * without limitation the rights to use, copy, modify, merge, publish,
11
 * distribute, sub license, and/or sell copies of the Software, and to
11
 * distribute, sub license, and/or sell copies of the Software, and to
12
 * permit persons to whom the Software is furnished to do so, subject to
12
 * permit persons to whom the Software is furnished to do so, subject to
13
 * the following conditions:
13
 * the following conditions:
14
 *
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
19
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22
 *
22
 *
23
 * The above copyright notice and this permission notice (including the
23
 * The above copyright notice and this permission notice (including the
24
 * next paragraph) shall be included in all copies or substantial portions
24
 * next paragraph) shall be included in all copies or substantial portions
25
 * of the Software.
25
 * of the Software.
26
 *
26
 *
27
 **************************************************************************/
27
 **************************************************************************/
28
 
28
 
29
 
29
 
30
#include "pipe/p_config.h"
30
#include "pipe/p_config.h"
31
#include "pipe/p_compiler.h"
31
#include "pipe/p_compiler.h"
32
 
-
 
33
#if defined(PIPE_OS_UNIX)
-
 
34
#include 
-
 
35
#endif
-
 
36
#if defined(PIPE_OS_WINDOWS)
-
 
37
#include 
-
 
38
#endif
32
 
39
 
33
 
40
#include "u_dl.h"
34
#include "u_dl.h"
41
#include "u_pointer.h"
35
#include "u_pointer.h"
-
 
36
 
-
 
37
void* load_library(const char *name);
42
 
38
void *get_proc_address(void *module, const char *proc_name);
43
 
39
 
44
struct util_dl_library *
40
struct util_dl_library *
45
util_dl_open(const char *filename)
41
util_dl_open(const char *filename)
46
{
42
{
47
#if defined(PIPE_OS_UNIX)
-
 
48
   return (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
-
 
49
#elif defined(PIPE_OS_WINDOWS)
-
 
50
   return (struct util_dl_library *)LoadLibraryA(filename);
43
   return (struct util_dl_library *)load_library(filename);
51
#else
-
 
52
   return NULL;
-
 
53
#endif
-
 
54
}
44
}
55
 
45
 
56
 
46
 
57
util_dl_proc
47
util_dl_proc
58
util_dl_get_proc_address(struct util_dl_library *library,
48
util_dl_get_proc_address(struct util_dl_library *library,
59
                         const char *procname)
49
                         const char *procname)
60
{
50
{
61
#if defined(PIPE_OS_UNIX)
-
 
62
   return (util_dl_proc) pointer_to_func(dlsym((void *)library, procname));
-
 
63
#elif defined(PIPE_OS_WINDOWS)
-
 
64
   return (util_dl_proc)GetProcAddress((HMODULE)library, procname);
51
   return (util_dl_proc)get_proc_address(library, procname);
65
#else
-
 
66
   return (util_dl_proc)NULL;
-
 
67
#endif
-
 
68
}
52
}
69
 
53
 
70
 
54
 
71
void
55
void
72
util_dl_close(struct util_dl_library *library)
56
util_dl_close(struct util_dl_library *library)
73
{
57
{
74
#if defined(PIPE_OS_UNIX)
-
 
75
   dlclose((void *)library);
-
 
76
#elif defined(PIPE_OS_WINDOWS)
-
 
77
   FreeLibrary((HMODULE)library);
-
 
78
#else
-
 
79
   (void)library;
58
   (void)library;
80
#endif
-
 
81
}
59
}
82
 
60
 
83
 
61
 
84
const char *
62
const char *
85
util_dl_error(void)
63
util_dl_error(void)
86
{
64
{
87
#if defined(PIPE_OS_UNIX)
-
 
88
   return dlerror();
-
 
89
#elif defined(PIPE_OS_WINDOWS)
-
 
90
   return "unknown error";
65
   return "unknown error";
91
#else
-
 
92
   return "unknown error";
-
 
93
#endif
-
 
94
}
66
}