Code::Blocks  SVN r11506
prefix.h
Go to the documentation of this file.
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 source code is public domain. You can relicense this code
8  * under whatever license you want.
9  *
10  * See http://autopackage.org/docs/binreloc/ for
11  * more information and how to use this.
12  *
13  * NOTE: if you're using C++ and are getting "undefined reference
14  * to br_*", try renaming prefix.c to prefix.cpp
15  */
16 
17 #ifndef _PREFIX_H_
18 #define _PREFIX_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
23 
24 /* WARNING, BEFORE YOU MODIFY PREFIX.C:
25  *
26  * If you make changes to any of the functions in prefix.c, you MUST
27  * change the BR_NAMESPACE macro.
28  * This way you can avoid symbol table conflicts with other libraries
29  * that also happen to use BinReloc.
30  *
31  * Example:
32  * #define BR_NAMESPACE(funcName) foobar_ ## funcName
33  * --> expands br_locate to foobar_br_locate
34  */
35 #undef BR_NAMESPACE
36 #define BR_NAMESPACE(funcName) funcName
37 
38 
39 #ifdef ENABLE_BINRELOC
40 
41 #define br_thread_local_store BR_NAMESPACE(br_thread_local_store)
42 #define br_locate BR_NAMESPACE(br_locate)
43 #define br_locate_prefix BR_NAMESPACE(br_locate_prefix)
44 #define br_prepend_prefix BR_NAMESPACE(br_prepend_prefix)
45 
46 #ifndef BR_NO_MACROS
47  /* These are convience macros that replace the ones usually used
48  in Autoconf/Automake projects */
49  #undef SELFPATH
50  #undef PREFIX
51  #undef PREFIXDIR
52  #undef BINDIR
53  #undef SBINDIR
54  #undef DATADIR
55  #undef LIBDIR
56  #undef LIBEXECDIR
57  #undef ETCDIR
58  #undef SYSCONFDIR
59  #undef CONFDIR
60  #undef LOCALEDIR
61 
62  #define SELFPATH (br_thread_local_store (br_locate ((void *) "")))
63  #define PREFIX (br_thread_local_store (br_locate_prefix ((void *) "")))
64  #define PREFIXDIR (br_thread_local_store (br_locate_prefix ((void *) "")))
65  #define BINDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/bin")))
66  #define SBINDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/sbin")))
67  #define DATADIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/share")))
68  #define LIBDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/lib")))
69  #define LIBEXECDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/libexec")))
70  #define ETCDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
71  #define SYSCONFDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
72  #define CONFDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
73  #define LOCALEDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/share/locale")))
74 #endif /* BR_NO_MACROS */
75 
76 
77 /* The following functions are used internally by BinReloc
78  and shouldn't be used directly in applications. */
79 
80 const char *br_thread_local_store (char *str);
81 char *br_locate (void *symbol);
82 char *br_locate_prefix (void *symbol);
83 char *br_prepend_prefix (void *symbol, char *path);
84 
85 
86 #endif /* ENABLE_BINRELOC */
87 
88 
89 /* These macros and functions are not guarded by the ENABLE_BINRELOC
90  * macro because they are portable. You can use these functions.
91  */
92 
93 #define br_strcat BR_NAMESPACE(br_strcat)
94 #define br_extract_dir BR_NAMESPACE(br_extract_dir)
95 #define br_extract_prefix BR_NAMESPACE(br_extract_prefix)
96 
97 #ifndef BR_NO_MACROS
98  /* Convenience functions for concatenating paths */
99  #define BR_SELFPATH(suffix) (br_thread_local_store (br_strcat (SELFPATH, suffix)))
100  #define BR_PREFIX(suffix) (br_thread_local_store (br_strcat (PREFIX, suffix)))
101  #define BR_PREFIXDIR(suffix) (br_thread_local_store (br_strcat (BR_PREFIX, suffix)))
102  #define BR_BINDIR(suffix) (br_thread_local_store (br_strcat (BINDIR, suffix)))
103  #define BR_SBINDIR(suffix) (br_thread_local_store (br_strcat (SBINDIR, suffix)))
104  #define BR_DATADIR(suffix) (br_thread_local_store (br_strcat (DATADIR, suffix)))
105  #define BR_LIBDIR(suffix) (br_thread_local_store (br_strcat (LIBDIR, suffix)))
106  #define BR_LIBEXECDIR(suffix) (br_thread_local_store (br_strcat (LIBEXECDIR, suffix)))
107  #define BR_ETCDIR(suffix) (br_thread_local_store (br_strcat (ETCDIR, suffix)))
108  #define BR_SYSCONFDIR(suffix) (br_thread_local_store (br_strcat (SYSCONFDIR, suffix)))
109  #define BR_CONFDIR(suffix) (br_thread_local_store (br_strcat (CONFDIR, suffix)))
110  #define BR_LOCALEDIR(suffix) (br_thread_local_store (br_strcat (LOCALEDIR, suffix)))
111 #endif
112 
113 char *br_strcat (const char *str1, const char *str2);
114 char *br_extract_dir (const char *path);
115 char *br_extract_prefix(const char *path);
116 
117 
118 #ifdef __cplusplus
119 }
120 #endif /* __cplusplus */
121 
122 #endif /* _PREFIX_H_ */
#define br_strcat
Definition: prefix.h:93
#define br_extract_dir
Definition: prefix.h:94
const char * br_thread_local_store(char *str)
br_thread_local_store: str: A dynamically allocated string.
Definition: prefix.cpp:298
#define br_extract_prefix
Definition: prefix.h:95