1 /*
2  * BinReloc - a library for creating relocatable executables
3  * Written by: Mike Hearn <mike@theoretic.com>
4  *             Hongli Lai <h.lai@chello.nl>
5  * http://autopackage.org/
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 3 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * See http://autopackage.org/docs/binreloc/ for
23  * more information and how to use this.
24  *
25  * NOTE: if you're using C++ and are getting "undefined reference
26  * to br_*", try renaming prefix.c to prefix.cpp
27  */
28 
29 #ifndef _PREFIX_H_
30 #define _PREFIX_H_
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35 
36 /* WARNING, BEFORE YOU MODIFY PREFIX.C:
37  *
38  * If you make changes to any of the functions in prefix.c, you MUST
39  * change the BR_NAMESPACE macro.
40  * This way you can avoid symbol table conflicts with other libraries
41  * that also happen to use BinReloc.
42  *
43  * Example:
44  * #define BR_NAMESPACE(funcName) foobar_ ## funcName
45  * --> expands br_locate to foobar_br_locate
46  */
47 #undef BR_NAMESPACE
48 #define BR_NAMESPACE(funcName) funcName
49 
50 
51 #ifdef ENABLE_BINRELOC
52 
53 #define br_thread_local_store BR_NAMESPACE(br_thread_local_store)
54 #define br_locate BR_NAMESPACE(br_locate)
55 #define br_locate_prefix BR_NAMESPACE(br_locate_prefix)
56 #define br_prepend_prefix BR_NAMESPACE(br_prepend_prefix)
57 
58 /* These are convience macros that replace the ones usually used
59    in Autoconf/Automake projects */
60 #undef SELFPATH
61 #undef PREFIX
62 #undef PREFIXDIR
63 #undef BINDIR
64 #undef SBINDIR
65 #undef DATADIR
66 #undef LIBDIR
67 #undef LIBEXECDIR
68 #undef ETCDIR
69 #undef SYSCONFDIR
70 #undef CONFDIR
71 #undef LOCALEDIR
72 
73 #define SELFPATH	(br_thread_local_store (br_locate ((void *) "")))
74 #define PREFIX		(br_thread_local_store (br_locate_prefix ((void *) "")))
75 #define PREFIXDIR	(br_thread_local_store (br_locate_prefix ((void *) "")))
76 #define BINDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/bin")))
77 #define SBINDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/sbin")))
78 #define DATADIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/share")))
79 #define LIBDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/lib")))
80 #define LIBEXECDIR	(br_thread_local_store (br_prepend_prefix ((void *) "", "/libexec")))
81 #define ETCDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
82 #define SYSCONFDIR	(br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
83 #define CONFDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
84 #define LOCALEDIR	(br_thread_local_store (br_prepend_prefix ((void *) "", "/share/locale")))
85 
86 /* The following functions are used internally by BinReloc
87    and shouldn't be used directly in applications. */
88 
89 const char *br_thread_local_store (char *str);
90 char *br_locate		(void *symbol);
91 char *br_locate_prefix	(void *symbol);
92 char *br_prepend_prefix	(void *symbol, char *path);
93 
94 
95 #endif /* ENABLE_BINRELOC */
96 
97 
98 /* These macros and functions are not guarded by the ENABLE_BINRELOC
99  * macro because they are portable. You can use these functions.
100  */
101 
102 #define br_strcat BR_NAMESPACE(br_strcat)
103 #define br_extract_dir BR_NAMESPACE(br_extract_dir)
104 #define br_extract_prefix BR_NAMESPACE(br_extract_prefix)
105 
106 /* Convenience functions for concatenating paths */
107 #define BR_SELFPATH(suffix)	(br_thread_local_store (br_strcat (SELFPATH, suffix)))
108 #define BR_PREFIX(suffix)	(br_thread_local_store (br_strcat (PREFIX, suffix)))
109 #define BR_PREFIXDIR(suffix)	(br_thread_local_store (br_strcat (BR_PREFIX, suffix)))
110 #define BR_BINDIR(suffix)	(br_thread_local_store (br_strcat (BINDIR, suffix)))
111 #define BR_SBINDIR(suffix)	(br_thread_local_store (br_strcat (SBINDIR, suffix)))
112 #define BR_DATADIR(suffix)	(br_thread_local_store (br_strcat (DATADIR, suffix)))
113 #define BR_LIBDIR(suffix)	(br_thread_local_store (br_strcat (LIBDIR, suffix)))
114 #define BR_LIBEXECDIR(suffix)	(br_thread_local_store (br_strcat (LIBEXECDIR, suffix)))
115 #define BR_ETCDIR(suffix)	(br_thread_local_store (br_strcat (ETCDIR, suffix)))
116 #define BR_SYSCONFDIR(suffix)	(br_thread_local_store (br_strcat (SYSCONFDIR, suffix)))
117 #define BR_CONFDIR(suffix)	(br_thread_local_store (br_strcat (CONFDIR, suffix)))
118 #define BR_LOCALEDIR(suffix)	(br_thread_local_store (br_strcat (LOCALEDIR, suffix)))
119 
120 char *br_strcat	(const char *str1, const char *str2);
121 char *br_extract_dir	(const char *path);
122 char *br_extract_prefix(const char *path);
123 
124 
125 #ifdef __cplusplus
126 }
127 #endif /* __cplusplus */
128 
129 #endif /* _PREFIX_H_ */
130