revert of mass delete of the posix subsystem. perhaps there is hope for it yet.
[reactos.git] / posix / lib / psxdll / dlfcn / dlsym.c
1 /* $Id: dlsym.c,v 1.4 2002/10/29 04:45:30 rex Exp $
2 */
3 /*
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: subsys/psx/lib/psxdll/dlfcn/dlsym.c
7 * PURPOSE: Obtain the address of a symbol from a dlopen() object
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
9 * UPDATE HISTORY:
10 * 19/12/2001: Created
11 */
12
13 #include <ddk/ntddk.h>
14 #include <ntdll/rtl.h>
15 #include <ntdll/ldr.h>
16 #include <dlfcn.h>
17 #include <psx/dlfcn.h>
18 #include <psx/errno.h>
19 #include <psx/debug.h>
20
21 void *__dlsymn(void *, unsigned long int);
22 void *__dlsym(void *, int, const char *, unsigned long int);
23
24 void *dlsym(void *handle, const char *name)
25 {
26 return (__dlsym(handle, 1, name, 0));
27 }
28
29 void *__dlsymn(void *handle, unsigned long int ordinal)
30 {
31 return (__dlsym(handle, 0, 0, ordinal));
32 }
33
34 void *__dlsym(void *handle, int by_name, const char *name, unsigned long int ordinal)
35 {
36 struct __dlobj * pdloObject;
37
38 void * pProcAddr;
39 NTSTATUS nErrCode;
40
41 if(handle == RTLD_NEXT)
42 {
43 FIXME("implement RTLD_NEXT semantics");
44 return (NULL);
45 }
46
47 pdloObject = (struct __dlobj *) handle;
48
49 if(pdloObject->global)
50 {
51 FIXME("implement global symbol matching");
52 return (NULL);
53 }
54
55 if(by_name)
56 {
57 ANSI_STRING strName;
58
59 RtlInitAnsiString(&strName, (LPSTR)name);
60
61 nErrCode = LdrGetProcedureAddress
62 (
63 pdloObject->handle,
64 &strName,
65 0,
66 (PVOID *)&pProcAddr
67 );
68
69 }
70 else
71 {
72 nErrCode = LdrGetProcedureAddress
73 (
74 pdloObject->handle,
75 NULL,
76 ordinal,
77 (PVOID *)&pProcAddr
78 );
79 }
80
81 if(!NT_SUCCESS(nErrCode))
82 {
83 __dl_set_last_error(__status_to_errno(nErrCode));
84 return (NULL);
85 }
86
87 return pProcAddr;
88
89 }
90
91 /* EOF */
92