1 /* Copyright (C) 2000-2007, Luca Padovani <padovani@sti.uniurb.it>.
2  *
3  * This file is part of GtkMathView, a flexible, high-quality rendering
4  * engine for MathML documents.
5  *
6  * GtkMathView is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published
8  * by the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GtkMathView is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef _PREFIX_H_
21 #define _PREFIX_H_
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26 
27 /* WARNING, BEFORE YOU MODIFY PREFIX.C:
28  *
29  * If you make changes to any of the functions in prefix.c, you MUST
30  * change the BR_NAMESPACE macro.
31  * This way you can avoid symbol table conflicts with other libraries
32  * that also happen to use BinReloc.
33  *
34  * Example:
35  * #define BR_NAMESPACE(funcName) foobar_ ## funcName
36  * --> expands br_locate to foobar_br_locate
37  */
38 #undef BR_NAMESPACE
39 #define BR_NAMESPACE(funcName) funcName
40 
41 
42 #ifdef ENABLE_BINRELOC
43 
44 #define br_thread_local_store BR_NAMESPACE(br_thread_local_store)
45 #define br_locate BR_NAMESPACE(br_locate)
46 #define br_locate_prefix BR_NAMESPACE(br_locate_prefix)
47 #define br_prepend_prefix BR_NAMESPACE(br_prepend_prefix)
48 
49 #ifndef BR_NO_MACROS
50 	/* These are convience macros that replace the ones usually used
51 	   in Autoconf/Automake projects */
52 	#undef SELFPATH
53 	#undef PREFIX
54 	#undef PREFIXDIR
55 	#undef BINDIR
56 	#undef SBINDIR
57 	#undef DATADIR
58 	#undef LIBDIR
59 	#undef LIBEXECDIR
60 	#undef ETCDIR
61 	#undef SYSCONFDIR
62 	#undef CONFDIR
63 	#undef LOCALEDIR
64 
65 	#define SELFPATH	(br_thread_local_store (br_locate ((void *) "")))
66 	#define PREFIX		(br_thread_local_store (br_locate_prefix ((void *) "")))
67 	#define PREFIXDIR	(br_thread_local_store (br_locate_prefix ((void *) "")))
68 	#define BINDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/bin")))
69 	#define SBINDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/sbin")))
70 	#define DATADIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/share")))
71 	#define LIBDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/lib")))
72 	#define LIBEXECDIR	(br_thread_local_store (br_prepend_prefix ((void *) "", "/libexec")))
73 	#define ETCDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
74 	#define SYSCONFDIR	(br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
75 	#define CONFDIR		(br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
76 	#define LOCALEDIR	(br_thread_local_store (br_prepend_prefix ((void *) "", "/share/locale")))
77 #endif /* BR_NO_MACROS */
78 
79 
80 /* The following functions are used internally by BinReloc
81    and shouldn't be used directly in applications. */
82 
83 char *br_locate		(void *symbol);
84 char *br_locate_prefix	(void *symbol);
85 char *br_prepend_prefix	(void *symbol, char *path);
86 
87 #endif /* ENABLE_BINRELOC */
88 
89 const char *br_thread_local_store (char *str);
90 
91 
92 /* These macros and functions are not guarded by the ENABLE_BINRELOC
93  * macro because they are portable. You can use these functions.
94  */
95 
96 #define br_strcat BR_NAMESPACE(br_strcat)
97 #define br_extract_dir BR_NAMESPACE(br_extract_dir)
98 #define br_extract_prefix BR_NAMESPACE(br_extract_prefix)
99 #define br_set_locate_fallback_func BR_NAMESPACE(br_set_locate_fallback_func)
100 
101 #ifndef BR_NO_MACROS
102   #ifndef ENABLE_BINRELOC
103 	#define BR_SELFPATH(suffix)	SELFPATH suffix
104 	#define BR_PREFIX(suffix)	PREFIX suffix
105 	#define BR_PREFIXDIR(suffix)	BR_PREFIX suffix
106 	#define BR_BINDIR(suffix)	BINDIR suffix
107 	#define BR_SBINDIR(suffix)	SBINDIR suffix
108 	#define BR_DATADIR(suffix)	DATADIR suffix
109 	#define BR_LIBDIR(suffix)	LIBDIR suffix
110 	#define BR_LIBEXECDIR(suffix)	LIBEXECDIR suffix
111 	#define BR_ETCDIR(suffix)	ETCDIR suffix
112 	#define BR_SYSCONFDIR(suffix)	SYSCONFDIR suffix
113 	#define BR_CONFDIR(suffix)	CONFDIR suffix
114 	#define BR_LOCALEDIR(suffix)	LOCALEDIR suffix
115   #else
116 	#define BR_SELFPATH(suffix)	(br_thread_local_store (br_strcat (SELFPATH, suffix)))
117 	#define BR_PREFIX(suffix)	(br_thread_local_store (br_strcat (PREFIX, suffix)))
118 	#define BR_PREFIXDIR(suffix)	(br_thread_local_store (br_strcat (BR_PREFIX, suffix)))
119 	#define BR_BINDIR(suffix)	(br_thread_local_store (br_strcat (BINDIR, suffix)))
120 	#define BR_SBINDIR(suffix)	(br_thread_local_store (br_strcat (SBINDIR, suffix)))
121 	#define BR_DATADIR(suffix)	(br_thread_local_store (br_strcat (DATADIR, suffix)))
122 	#define BR_LIBDIR(suffix)	(br_thread_local_store (br_strcat (LIBDIR, suffix)))
123 	#define BR_LIBEXECDIR(suffix)	(br_thread_local_store (br_strcat (LIBEXECDIR, suffix)))
124 	#define BR_ETCDIR(suffix)	(br_thread_local_store (br_strcat (ETCDIR, suffix)))
125 	#define BR_SYSCONFDIR(suffix)	(br_thread_local_store (br_strcat (SYSCONFDIR, suffix)))
126 	#define BR_CONFDIR(suffix)	(br_thread_local_store (br_strcat (CONFDIR, suffix)))
127 	#define BR_LOCALEDIR(suffix)	(br_thread_local_store (br_strcat (LOCALEDIR, suffix)))
128   #endif
129 #endif
130 
131 char *br_strcat	(const char *str1, const char *str2);
132 char *br_extract_dir	(const char *path);
133 char *br_extract_prefix(const char *path);
134 typedef char *(*br_locate_fallback_func) (void *symbol, void *data);
135 void br_set_locate_fallback_func (br_locate_fallback_func func, void *data);
136 
137 
138 #ifdef __cplusplus
139 }
140 #endif /* __cplusplus */
141 
142 #endif /* _PREFIX_H_ */
143