]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/system.h
451309e7dd781d239ddf60c79568c7f200eb3373
[thirdparty/binutils-gdb.git] / gold / system.h
1 // system.h -- general definitions for gold -*- C++ -*-
2
3 // Copyright (C) 2006-2022 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #ifndef SYSTEM_H
24 #define SYSTEM_H 1
25
26 #ifndef ENABLE_NLS
27 // The Solaris version of locale.h always includes libintl.h. If we
28 // have been configured with --disable-nls then ENABLE_NLS will not
29 // be defined and the dummy definitions of bindtextdomain (et al)
30 // below will conflict with the definitions in libintl.h. So we
31 // define these values to prevent the bogus inclusion of libintl.h.
32 # define _LIBINTL_H
33 # define _LIBGETTEXT_H
34 #endif
35
36 #ifdef ENABLE_NLS
37 // On some systems, things go awry when <libintl.h> comes after <clocale>.
38 # include <libintl.h>
39 # include <clocale>
40 # define _(String) gettext (String)
41 # ifdef gettext_noop
42 # define N_(String) gettext_noop (String)
43 # else
44 # define N_(String) (String)
45 # endif
46 #else
47 // Include <clocale> first to avoid conflicts with these macros.
48 # include <clocale>
49 # define gettext(Msgid) (Msgid)
50 # define dgettext(Domainname, Msgid) (Msgid)
51 # define dcgettext(Domainname, Msgid, Category) (Msgid)
52 # define ngettext(Msgid1, Msgid2, n) \
53 (n == 1 ? Msgid1 : Msgid2)
54 # define dngettext(Domainname, Msgid1, Msgid2, n) \
55 (n == 1 ? Msgid1 : Msgid2)
56 # define dcngettext(Domainname, Msgid1, Msgid2, n, Category) \
57 (n == 1 ? Msgid1 : Msgid2)
58 # define textdomain(Domainname) do {} while (0)
59 # define bindtextdomain(Domainname, Dirname) do {} while (0)
60 # define _(String) (String)
61 # define N_(String) (String)
62 #endif
63
64 // Figure out how to get a hash set and a hash map.
65
66 #if defined(HAVE_UNORDERED_SET) && defined(HAVE_UNORDERED_MAP)
67
68 #include <unordered_set>
69 #include <unordered_map>
70
71 // We need a template typedef here.
72
73 #define Unordered_set std::unordered_set
74 #define Unordered_map std::unordered_map
75 #define Unordered_multimap std::unordered_multimap
76
77 #define reserve_unordered_map(map, n) ((map)->rehash(n))
78
79 #elif defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP) \
80 && defined(HAVE_TR1_UNORDERED_MAP_REHASH)
81
82 #include <tr1/unordered_set>
83 #include <tr1/unordered_map>
84
85 // We need a template typedef here.
86
87 #define Unordered_set std::tr1::unordered_set
88 #define Unordered_map std::tr1::unordered_map
89 #define Unordered_multimap std::tr1::unordered_multimap
90
91 #define reserve_unordered_map(map, n) ((map)->rehash(n))
92
93 #ifndef HAVE_TR1_HASH_OFF_T
94 // The library does not support hashes of off_t values. Add support
95 // here. This is likely to be specific to libstdc++. This issue
96 // arises with GCC 4.1.x when compiling in 32-bit mode with a 64-bit
97 // off_t type.
98 namespace std { namespace tr1 {
99 template<>
100 struct hash<off_t> : public std::unary_function<off_t, std::size_t>
101 {
102 std::size_t
103 operator()(off_t val) const
104 { return static_cast<std::size_t>(val); }
105 };
106 } } // Close namespaces.
107 #endif // !defined(HAVE_TR1_HASH_OFF_T)
108
109 #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
110
111 #include <ext/hash_map>
112 #include <ext/hash_set>
113 #include <string>
114
115 #define Unordered_set __gnu_cxx::hash_set
116 #define Unordered_map __gnu_cxx::hash_map
117 #define Unordered_multimap __gnu_cxx::hash_multimap
118
119 namespace __gnu_cxx
120 {
121
122 template<>
123 struct hash<std::string>
124 {
125 size_t
126 operator()(std::string s) const
127 { return __stl_hash_string(s.c_str()); }
128 };
129
130 template<typename T>
131 struct hash<T*>
132 {
133 size_t
134 operator()(T* p) const
135 { return reinterpret_cast<size_t>(p); }
136 };
137
138 }
139
140 #define reserve_unordered_map(map, n) ((map)->resize(n))
141
142 #else
143
144 // The fallback is to just use set and map.
145
146 #include <set>
147 #include <map>
148
149 #define Unordered_set std::set
150 #define Unordered_map std::map
151 #define Unordered_multimap std::multimap
152
153 #define reserve_unordered_map(map, n)
154
155 #endif
156
157 #ifndef HAVE_PREAD
158 extern "C" ssize_t pread(int, void*, size_t, off_t);
159 #endif
160
161 #ifndef HAVE_FTRUNCATE
162 extern "C" int ftruncate(int, off_t);
163 #endif
164
165 #ifndef HAVE_FFSLL
166 extern "C" int ffsll(long long);
167 #endif
168
169 #if !HAVE_DECL_MEMMEM
170 extern "C" void *memmem(const void *, size_t, const void *, size_t);
171 #endif
172
173 #if !HAVE_DECL_STRNDUP
174 extern "C" char *strndup(const char *, size_t);
175 #endif
176
177 #endif // !defined(SYSTEM_H)