relocatable.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Provide relocatable packages.
  2. Copyright (C) 2003, 2005, 2008 Free Software Foundation, Inc.
  3. Written by Bruno Haible <bruno@clisp.org>, 2003.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU General Public
  13. License along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  15. USA. */
  16. #ifndef _RELOCATABLE_H
  17. #define _RELOCATABLE_H
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /* This can be enabled through the configure --enable-relocatable option. */
  22. #if ENABLE_RELOCATABLE
  23. /* When building a DLL, we must export some functions. Note that because
  24. this is a private .h file, we don't need to use __declspec(dllimport)
  25. in any case. */
  26. #if HAVE_VISIBILITY && BUILDING_DLL
  27. # define RELOCATABLE_DLL_EXPORTED __attribute__((__visibility__("default")))
  28. #elif defined _MSC_VER && BUILDING_DLL
  29. # define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
  30. #else
  31. # define RELOCATABLE_DLL_EXPORTED
  32. #endif
  33. /* Sets the original and the current installation prefix of the package.
  34. Relocation simply replaces a pathname starting with the original prefix
  35. by the corresponding pathname with the current prefix instead. Both
  36. prefixes should be directory names without trailing slash (i.e. use ""
  37. instead of "/"). */
  38. extern RELOCATABLE_DLL_EXPORTED void
  39. set_relocation_prefix (const char *orig_prefix,
  40. const char *curr_prefix);
  41. /* Returns the pathname, relocated according to the current installation
  42. directory.
  43. The returned string is either PATHNAME unmodified or a freshly allocated
  44. string that you can free with free() after casting it to 'char *'. */
  45. extern const char * relocate (const char *pathname);
  46. /* Memory management: relocate() potentially allocates memory, because it has
  47. to construct a fresh pathname. If this is a problem because your program
  48. calls relocate() frequently, think about caching the result. Or free the
  49. return value if it was different from the argument pathname. */
  50. /* Convenience function:
  51. Computes the current installation prefix, based on the original
  52. installation prefix, the original installation directory of a particular
  53. file, and the current pathname of this file.
  54. Returns it, freshly allocated. Returns NULL upon failure. */
  55. extern char * compute_curr_prefix (const char *orig_installprefix,
  56. const char *orig_installdir,
  57. const char *curr_pathname);
  58. #else
  59. /* By default, we use the hardwired pathnames. */
  60. #define relocate(pathname) (pathname)
  61. #endif
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif /* _RELOCATABLE_H */