findsym.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
  25. /* All Rights Reserved */
  26. /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
  27. /* UNIX System Laboratories, Inc. */
  28. /* The copyright notice above does not evidence any */
  29. /* actual or intended publication of such source code. */
  30. #include "stdio.h"
  31. #include <sys/types.h>
  32. #ifdef DYNLIB
  33. #ifdef __aix
  34. #include <sys/ldr.h>
  35. #else
  36. #include <dlfcn.h>
  37. #endif
  38. /* from ksh93/include/ast/shell.h */
  39. extern void **sh_getliblist(void);
  40. #endif
  41. #ifdef HPUX_DYNLIB
  42. #include <dl.h>
  43. #endif
  44. #include <string.h>
  45. #include <search.h>
  46. #include <ctype.h>
  47. #include "xmdtksym.h"
  48. #include "msgs.h"
  49. /*
  50. * This function is currently only used to locate a widget class record,
  51. * as requested by a DtLoadWidget request. In the future, if the exksh
  52. * commands are ever added back in, then it will also need to be able
  53. * to locate any arbitrary symbol.
  54. */
  55. unsigned long
  56. fsym(
  57. char *str,
  58. int lib )
  59. {
  60. #ifdef DYNLIB
  61. void ** liblist;
  62. int i = 0;
  63. long addr;
  64. #endif
  65. #ifdef HPUX_DYNLIB
  66. void *found;
  67. shl_t handle;
  68. #endif
  69. #ifdef DYNLIB
  70. if ((liblist = sh_getliblist()) == NULL)
  71. return(NULL);
  72. while (liblist[i])
  73. {
  74. if (addr = dlsym(liblist[i], str))
  75. return((unsigned long)addr);
  76. i++;
  77. }
  78. #else
  79. #ifdef HPUX_DYNLIB
  80. handle = NULL;
  81. if ((shl_findsym(&handle, str, TYPE_PROCEDURE, &found)) == 0)
  82. return((unsigned long) found);
  83. if ((shl_findsym(&handle, str, TYPE_DATA, &found)) == 0)
  84. return((unsigned long) found);
  85. handle = PROG_HANDLE;
  86. if ((shl_findsym(&handle, str, TYPE_PROCEDURE, &found)) == 0)
  87. return((unsigned long) found);
  88. if ((shl_findsym(&handle, str, TYPE_DATA, &found)) == 0)
  89. return((unsigned long) found);
  90. #endif
  91. #endif
  92. return(NULL);
  93. }