convert all Imakefile LinuxDistribution to LinuxArchitecture.
[oweals/cde.git] / cde / programs / dtksh / findsym.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: findsym.c /main/5 1995/11/09 09:32:59 rswiston $ */
24
25 /*      Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
26 /*      All Rights Reserved     */
27
28 /*      THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF    */
29 /*      UNIX System Laboratories, Inc.                  */
30 /*      The copyright notice above does not evidence any       */
31 /*      actual or intended publication of such source code.    */
32
33 #include "stdio.h"
34 #include <sys/types.h>
35
36 #ifdef DYNLIB
37 #ifdef __aix
38 #include <sys/ldr.h>
39 #else
40 #include <dlfcn.h>
41 #endif
42 /* from ksh93/include/ast/shell.h */
43 extern void **sh_getliblist(void);
44 #endif
45 #ifdef HPUX_DYNLIB
46 #include <dl.h>
47 #endif
48
49 #include <string.h>
50 #include <search.h>
51 #include <ctype.h>
52 #include "xmdtksym.h"
53 #include "msgs.h"
54
55 /*
56  * This function is currently only used to locate a widget class record,
57  * as requested by a DtLoadWidget request.  In the future, if the exksh
58  * commands are ever added back in, then it will also need to be able
59  * to locate any arbitrary symbol.
60  */
61
62 unsigned long
63 fsym(
64         char *str,
65         int lib )
66 {
67 #ifdef DYNLIB
68    void ** liblist;
69    int i = 0;
70    long addr;
71 #endif
72 #ifdef HPUX_DYNLIB
73    void *found;
74    shl_t handle;
75 #endif
76
77 #ifdef DYNLIB
78    if ((liblist = sh_getliblist()) == NULL)
79         return(NULL);
80
81    while (liblist[i])
82    {
83       if (addr = dlsym(liblist[i], str))
84          return((unsigned long)addr);
85       i++;
86    }
87 #else
88 #ifdef HPUX_DYNLIB
89    handle = NULL;
90    if ((shl_findsym(&handle, str, TYPE_PROCEDURE, &found)) == 0)
91       return((unsigned long) found);
92    if ((shl_findsym(&handle, str, TYPE_DATA, &found)) == 0)
93       return((unsigned long) found);
94    handle = PROG_HANDLE;
95    if ((shl_findsym(&handle, str, TYPE_PROCEDURE, &found)) == 0)
96       return((unsigned long) found);
97    if ((shl_findsym(&handle, str, TYPE_DATA, &found)) == 0)
98       return((unsigned long) found);
99 #endif
100 #endif
101
102    return(NULL);
103 }