]>
Commit | Line | Data |
---|---|---|
f04e1182 AJ |
1 | #ifndef SQUID_CONFIG_H |
2 | #include "config.h" | |
3 | #endif | |
4 | ||
5 | #ifndef _SQUID_COMPAT_SHARED_H | |
6 | #define _SQUID_COMPAT_SHARED_H | |
7 | ||
8 | /* | |
9 | * This file contains all the compatibility and portability hacks | |
10 | * Which are general-case and shared between all OS and support programs. | |
11 | * | |
12 | * If an OS-specific hack is needed there are per-OS files for that in | |
13 | * the os/ sub-directory here. | |
14 | * | |
15 | * These hacks should be platform and location agnostic. | |
16 | * A quick look-over of the code already here should give you an idea | |
17 | * of the requirements for wrapping your hack for safe portability. | |
18 | */ | |
19 | ||
20 | ||
21 | /* | |
22 | * sys/resource.h and sys/time.h are apparently order-dependant. | |
23 | */ | |
24 | #if HAVE_SYS_TIME_H | |
25 | #include <sys/time.h> | |
26 | #endif | |
27 | #if HAVE_SYS_RESOURCE_H | |
28 | #include <sys/resource.h> /* needs sys/time.h above it */ | |
29 | #endif | |
30 | ||
31 | /* | |
32 | * DIRENT functionality can apparently come from many places. | |
33 | * I believe these should really be done by OS-specific compat | |
34 | * files, but for now its left here. | |
35 | */ | |
36 | #if HAVE_DIRENT_H | |
37 | #include <dirent.h> | |
38 | #define NAMLEN(dirent) strlen((dirent)->d_name) | |
39 | ||
40 | #else /* if not HAVE_DIRENT_H */ | |
41 | #define dirent direct | |
42 | #define NAMLEN(dirent) (dirent)->d_namlen | |
43 | #if HAVE_SYS_NDIR_H | |
44 | #include <sys/ndir.h> | |
45 | #endif /* HAVE_SYS_NDIR_H */ | |
46 | #if HAVE_SYS_DIR_H | |
47 | #include <sys/dir.h> | |
48 | #endif /* HAVE_SYS_DIR_H */ | |
49 | #if HAVE_NDIR_H | |
50 | #include <ndir.h> | |
51 | #endif /* HAVE_NDIR_H */ | |
52 | #endif /* HAVE_DIRENT_H */ | |
53 | ||
54 | ||
55 | /* | |
56 | * Filedescriptor limits in the different select loops | |
cc937513 AJ |
57 | * |
58 | * NP: FreeBSD 7 defines FD_SETSIZE as unsigned but Squid needs | |
59 | * it to be signed to compare it with signed values. | |
60 | * Linux and others including FreeBSD <7, define it as signed. | |
61 | * If this causes any issues please contact squid-dev@squid-cache.org | |
f04e1182 AJ |
62 | */ |
63 | #if defined(USE_SELECT) || defined(USE_SELECT_WIN32) | |
64 | /* Limited by design */ | |
cc937513 | 65 | # define SQUID_MAXFD_LIMIT ((signed int)FD_SETSIZE) |
f04e1182 AJ |
66 | |
67 | #elif defined(USE_POLL) | |
68 | /* Limited due to delay pools */ | |
cc937513 | 69 | # define SQUID_MAXFD_LIMIT ((signed int)FD_SETSIZE) |
f04e1182 AJ |
70 | |
71 | #elif defined(USE_KQUEUE) || defined(USE_EPOLL) | |
72 | # define SQUID_FDSET_NOUSE 1 | |
73 | ||
74 | #else | |
75 | # error Unknown select loop model! | |
76 | #endif | |
77 | ||
78 | ||
79 | ||
80 | #if !HAVE_STRUCT_RUSAGE | |
81 | /** | |
82 | * If we don't have getrusage() then we create a fake structure | |
83 | * with only the fields Squid cares about. This just makes the | |
84 | * source code cleaner, so we don't need lots of #ifdefs in other | |
85 | * places | |
86 | */ | |
87 | struct rusage | |
88 | { | |
89 | struct timeval ru_stime; | |
90 | struct timeval ru_utime; | |
91 | int ru_maxrss; | |
92 | int ru_majflt; | |
93 | }; | |
94 | #endif /* !HAVE_STRUCT_RUSAGE */ | |
95 | ||
96 | ||
f04e1182 | 97 | #ifndef min |
d85c3078 | 98 | #ifdef __cplusplus |
f04e1182 AJ |
99 | /** |
100 | * min() comparison may not always be provided. | |
101 | * Squid bundles this template for when its needed. | |
102 | * May be used on any type which provides operator '<' | |
103 | */ | |
104 | template<class A> | |
105 | inline A const & | |
106 | min(A const & lhs, A const & rhs) | |
107 | { | |
108 | if (rhs < lhs) | |
109 | return rhs; | |
110 | return lhs; | |
111 | } | |
d85c3078 AJ |
112 | #else /* !__cplusplus */ |
113 | /* for non-C++ we are stuck with the < and ? operator */ | |
114 | #define min(a,b) ((a) < (b) ? (a) : (b)) | |
115 | #endif /* __cplusplus */ | |
116 | #endif /* min */ | |
f04e1182 AJ |
117 | |
118 | #ifndef max | |
d85c3078 | 119 | #ifdef __cplusplus |
f04e1182 AJ |
120 | /** |
121 | * max() comparison may not always be provided. | |
122 | * Squid bundles this template for when its needed. | |
123 | * May be used on any type which provides operator '>' | |
124 | */ | |
125 | template<class A> | |
126 | inline A const & | |
127 | max(A const & lhs, A const & rhs) | |
128 | { | |
129 | if (rhs > lhs) | |
130 | return rhs; | |
131 | return lhs; | |
132 | } | |
d85c3078 AJ |
133 | #else /* !__cplusplus */ |
134 | /* for non-C++ we are stuck with the < and ? operator */ | |
135 | #define max(a,b) ((a) < (b) ? (b) : (a)) | |
f04e1182 | 136 | #endif /* __cplusplus */ |
d85c3078 | 137 | #endif /* max */ |
f04e1182 AJ |
138 | |
139 | /** | |
140 | * tempnam() not provided by all systems | |
141 | * TODO: detect WHICH systems and move to their OS-specific compat files | |
142 | */ | |
143 | #if !HAVE_TEMPNAM | |
144 | #include "tempnam.h" | |
145 | #endif | |
146 | ||
147 | /** | |
148 | * strsep() not provided by all systems | |
149 | * TODO: detect WHICH systems and move to their OS-specific compat files | |
150 | */ | |
151 | #if !HAVE_STRSEP | |
152 | #include "strsep.h" | |
153 | #endif | |
154 | ||
155 | /** | |
156 | * strtoll() not provided by all systems | |
157 | * TODO: detect WHICH systems and move to their OS-specific compat files | |
158 | */ | |
159 | #if !HAVE_STRTOLL | |
160 | #include "strtoll.h" | |
161 | #endif | |
162 | ||
163 | /** | |
164 | * Common shared definition of what whitespace consists of for string tests | |
165 | */ | |
166 | #define w_space " \t\n\r" | |
167 | ||
168 | /** | |
169 | * initgroups() not provided by all systems | |
170 | * TODO: detect WHICH systems and move to their OS-specific compat files | |
171 | */ | |
172 | #if !HAVE_INITGROUPS | |
173 | #include "initgroups.h" | |
174 | #endif | |
175 | ||
176 | ||
177 | /* REQUIRED for the below logics. If they move this needs to as well */ | |
178 | #if HAVE_FCNTL_H | |
179 | #include <fcntl.h> | |
180 | #endif | |
181 | #if defined(O_NONBLOCK) | |
182 | /** | |
183 | * We used to assume O_NONBLOCK was broken on Solaris, but evidence | |
184 | * now indicates that its fine on Solaris 8, and in fact required for | |
185 | * properly detecting EOF on FIFOs. So now we assume that if | |
186 | * its defined, it works correctly on all operating systems. | |
187 | */ | |
188 | #define SQUID_NONBLOCK O_NONBLOCK | |
189 | #else | |
190 | /** O_NDELAY is our fallback. */ | |
191 | #define SQUID_NONBLOCK O_NDELAY | |
192 | #endif | |
193 | ||
194 | ||
195 | /** | |
196 | * Signalling flags are apparently not always provided. | |
197 | * TODO find out if these can be moved into specific OS portability files. | |
198 | */ | |
199 | #ifndef SA_RESTART | |
200 | #define SA_RESTART 0 | |
201 | #endif | |
202 | #ifndef SA_NODEFER | |
203 | #define SA_NODEFER 0 | |
204 | #endif | |
205 | #ifndef SA_RESETHAND | |
206 | #define SA_RESETHAND 0 | |
207 | #endif | |
208 | #if SA_RESETHAND == 0 && defined(SA_ONESHOT) | |
209 | #undef SA_RESETHAND | |
210 | #define SA_RESETHAND SA_ONESHOT | |
211 | #endif | |
212 | ||
213 | ||
214 | #endif /* _SQUID_COMPAT_SHARED_H */ |