relocatable.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Provide relocatable packages.
  2. Copyright (C) 2003 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 Library General Public License as published
  6. by the Free Software Foundation; either version 2, 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 Library General Public
  13. License along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  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 defined _MSC_VER && BUILDING_DLL
  27. # define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
  28. #else
  29. # define RELOCATABLE_DLL_EXPORTED
  30. #endif
  31. /* Sets the original and the current installation prefix of the package.
  32. Relocation simply replaces a pathname starting with the original prefix
  33. by the corresponding pathname with the current prefix instead. Both
  34. prefixes should be directory names without trailing slash (i.e. use ""
  35. instead of "/"). */
  36. extern RELOCATABLE_DLL_EXPORTED void
  37. set_relocation_prefix (const char *orig_prefix,
  38. const char *curr_prefix);
  39. /* Returns the pathname, relocated according to the current installation
  40. directory. */
  41. extern const char * relocate (const char *pathname);
  42. /* Memory management: relocate() leaks memory, because it has to construct
  43. a fresh pathname. If this is a problem because your program calls
  44. relocate() frequently, think about caching the result. */
  45. /* Convenience function:
  46. Computes the current installation prefix, based on the original
  47. installation prefix, the original installation directory of a particular
  48. file, and the current pathname of this file. Returns NULL upon failure. */
  49. extern const char * compute_curr_prefix (const char *orig_installprefix,
  50. const char *orig_installdir,
  51. const char *curr_pathname);
  52. #else
  53. /* By default, we use the hardwired pathnames. */
  54. #define relocate(pathname) (pathname)
  55. #endif
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif /* _RELOCATABLE_H */