home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / prlink.h < prev    next >
C/C++ Source or Header  |  1998-07-21  |  5KB  |  141 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef prlink_h___
  20. #define prlink_h___
  21.  
  22. /*
  23. ** API to static and dynamic linking.
  24. */
  25. #include "prtypes.h"
  26.  
  27. PR_BEGIN_EXTERN_C
  28.  
  29. typedef struct PRLibrary PRLibrary;
  30.  
  31. typedef struct PRStaticLinkTable {
  32.     const char *name;
  33.     void (*fp)();
  34. } PRStaticLinkTable;
  35.  
  36. /*
  37. ** Change the default library path to the given string. The string is
  38. ** copied. This call will fail if it runs out of memory.
  39. **
  40. ** The string provided as 'path' is copied. The caller can do whatever is
  41. ** convenient with the argument when the function is complete.
  42. */
  43. PR_EXTERN(PRStatus) PR_SetLibraryPath(const char *path);
  44.  
  45. /*
  46. ** Return a character string which contains the path used to search for
  47. ** dynamically loadable libraries.
  48. **
  49. ** The returned value is basically a copy of a PR_SetLibraryPath().
  50. ** The storage is allocated by the runtime and becomes the responsibilty
  51. ** of the caller.
  52. */
  53. PR_EXTERN(char*) PR_GetLibraryPath(void);
  54.  
  55. /*
  56. ** Given a directory name "dir" and a library name "lib" construct a full
  57. ** path name that will refer to the actual dynamically loaded
  58. ** library. This does not test for existance of said file, it just
  59. ** constructs the full filename. The name constructed is system dependent
  60. ** and prepared for PR_LoadLibrary. The result must be free'd when the
  61. ** caller is done with it.
  62. **
  63. ** The storage for the result is allocated by the runtime and becomes the
  64. ** responsibility of the caller.
  65. */
  66. PR_EXTERN(char*) PR_GetLibraryName(const char *dir, const char *lib);
  67.  
  68. /*
  69. **
  70. ** Free the memory allocated, for the caller, by PR_GetLibraryName
  71. */
  72. PR_EXTERN(void) PR_FreeLibraryName(char *mem);
  73.  
  74. /*
  75. ** Given a library "name" try to load the library. The argument "name"
  76. ** is a machine-dependent name for the library, such as the full pathname
  77. ** returned by PR_GetLibraryName.  If the library is already loaded,
  78. ** this function will avoid loading the library twice.
  79. **
  80. ** If the library is loaded successfully, then a pointer to the PRLibrary
  81. ** structure representing the library is returned.  Otherwise, NULL is
  82. ** returned.
  83. **
  84. ** This increments the reference count of the library.
  85. */
  86. PR_EXTERN(PRLibrary*) PR_LoadLibrary(const char *name);
  87.  
  88. /*
  89. ** Unload a previously loaded library. If the library was a static
  90. ** library then the static link table will no longer be referenced. The
  91. ** associated PRLibrary object is freed.
  92. **
  93. ** PR_FAILURE is returned if the library cannot be unloaded.
  94. **
  95. ** This function decrements the reference count of the library.
  96. */
  97. PR_EXTERN(PRStatus) PR_UnloadLibrary(PRLibrary *lib);
  98.  
  99. /*
  100. ** Given the name of a procedure, return the address of the function that
  101. ** implements the procedure, or NULL if no such function can be
  102. ** found. This does not find symbols in the main program (the ".exe");
  103. ** use PR_LoadStaticLibrary to register symbols in the main program.  If
  104. ** "lib" is NULL then all currently loaded libraries and the main program
  105. ** are searched.
  106. **
  107. ** This function does not modify the reference count of the library.
  108. */
  109. PR_EXTERN(void*) PR_FindSymbol(PRLibrary *lib, const char *name);
  110.  
  111. /*
  112. ** Finds a symbol in one of the currently loaded libraries. Given the
  113. ** name of a procedure, return the address of the function that
  114. ** implements the procedure, and return the library that contains that
  115. ** symbol, or NULL if no such function can be found. This does not find
  116. ** symbols in the main program (the ".exe"); use PR_AddStaticLibrary to
  117. ** register symbols in the main program.  
  118. **
  119. ** This increments the reference count of the library.
  120. */
  121. PR_EXTERN(void*) PR_FindSymbolAndLibrary(const char *name,
  122.                               PRLibrary* *lib);
  123.  
  124. /*
  125. ** Register a static link table with the runtime under the name
  126. ** "name". The symbols present in the static link table will be made
  127. ** available to PR_FindSymbol. If "name" is null then the symbols will be
  128. ** made available to the library which represents the executable. The
  129. ** tables are not copied.
  130. **
  131. ** Returns the library object if successful, null otherwise.
  132. **
  133. ** This increments the reference count of the library.
  134. */
  135. PR_EXTERN(PRLibrary*) PR_LoadStaticLibrary(
  136.     const char *name, const PRStaticLinkTable *table);
  137.  
  138. PR_END_EXTERN_C
  139.  
  140. #endif /* prlink_h___ */
  141.