Back to index

courier  0.68.2
relocatable.h
Go to the documentation of this file.
00001 /* Provide relocatable packages.
00002    Copyright (C) 2003, 2005, 2008 Free Software Foundation, Inc.
00003    Written by Bruno Haible <bruno@clisp.org>, 2003.
00004 
00005    This program is free software; you can redistribute it and/or modify it
00006    under the terms of the GNU Library General Public License as published
00007    by the Free Software Foundation; either version 2, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00018    USA.  */
00019 
00020 #ifndef _RELOCATABLE_H
00021 #define _RELOCATABLE_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 
00028 /* This can be enabled through the configure --enable-relocatable option.  */
00029 #if ENABLE_RELOCATABLE
00030 
00031 /* When building a DLL, we must export some functions.  Note that because
00032    this is a private .h file, we don't need to use __declspec(dllimport)
00033    in any case.  */
00034 #if HAVE_VISIBILITY && BUILDING_DLL
00035 # define RELOCATABLE_DLL_EXPORTED __attribute__((__visibility__("default")))
00036 #elif defined _MSC_VER && BUILDING_DLL
00037 # define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
00038 #else
00039 # define RELOCATABLE_DLL_EXPORTED
00040 #endif
00041 
00042 /* Sets the original and the current installation prefix of the package.
00043    Relocation simply replaces a pathname starting with the original prefix
00044    by the corresponding pathname with the current prefix instead.  Both
00045    prefixes should be directory names without trailing slash (i.e. use ""
00046    instead of "/").  */
00047 extern RELOCATABLE_DLL_EXPORTED void
00048        set_relocation_prefix (const char *orig_prefix,
00049                               const char *curr_prefix);
00050 
00051 /* Returns the pathname, relocated according to the current installation
00052    directory.
00053    The returned string is either PATHNAME unmodified or a freshly allocated
00054    string that you can free with free() after casting it to 'char *'.  */
00055 extern const char * relocate (const char *pathname);
00056 
00057 /* Memory management: relocate() potentially allocates memory, because it has
00058    to construct a fresh pathname.  If this is a problem because your program
00059    calls relocate() frequently, think about caching the result.  Or free the
00060    return value if it was different from the argument pathname.  */
00061 
00062 /* Convenience function:
00063    Computes the current installation prefix, based on the original
00064    installation prefix, the original installation directory of a particular
00065    file, and the current pathname of this file.
00066    Returns it, freshly allocated.  Returns NULL upon failure.  */
00067 extern char * compute_curr_prefix (const char *orig_installprefix,
00068                                    const char *orig_installdir,
00069                                    const char *curr_pathname);
00070 
00071 #else
00072 
00073 /* By default, we use the hardwired pathnames.  */
00074 #define relocate(pathname) (pathname)
00075 
00076 #endif
00077 
00078 
00079 #ifdef __cplusplus
00080 }
00081 #endif
00082 
00083 #endif /* _RELOCATABLE_H */