]>
git.ipfire.org Git - thirdparty/squid.git/blob - compat/compat_shared.h
1 #ifndef _SQUID_COMPAT_SHARED_H
2 #define _SQUID_COMPAT_SHARED_H
5 * This file contains all the compatibility and portability hacks
6 * Which are general-case and shared between all OS and support programs.
8 * If an OS-specific hack is needed there are per-OS files for that in
9 * the os/ sub-directory here.
11 * These hacks should be platform and location agnostic.
12 * A quick look-over of the code already here should give you an idea
13 * of the requirements for wrapping your hack for safe portability.
18 * Define an error display handler override.
19 * If error_notify is set by the linked program it will be used by the local
20 * portability functions. Otherwise perror() will be used.
22 extern void (*failure_notify
) (const char *);
26 * sys/resource.h and sys/time.h are apparently order-dependant.
31 #if HAVE_SYS_RESOURCE_H
32 #include <sys/resource.h> /* needs sys/time.h above it */
36 * DIRENT functionality can apparently come from many places.
37 * With various complaints by different compilers
41 #define NAMLEN(dirent) strlen((dirent)->d_name)
42 #else /* if not HAVE_DIRENT_H */
44 #define NAMLEN(dirent) (dirent)->d_namlen
47 #endif /* HAVE_SYS_NDIR_H */
50 #endif /* HAVE_SYS_DIR_H */
53 #endif /* HAVE_NDIR_H */
54 #endif /* HAVE_DIRENT_H */
56 /* The structure dirent also varies between 64-bit and 32-bit environments.
57 * Define our own dirent_t type for consistent simple internal use.
58 * NP: GCC seems not to care about the type naming differences.
60 #if defined(__USE_FILE_OFFSET64) && !defined(__GNUC__)
61 #define dirent_t struct dirent64
63 #define dirent_t struct dirent
67 * Filedescriptor limits in the different select loops
69 * NP: FreeBSD 7 defines FD_SETSIZE as unsigned but Squid needs
70 * it to be signed to compare it with signed values.
71 * Linux and others including FreeBSD <7, define it as signed.
72 * If this causes any issues please contact squid-dev@squid-cache.org
74 #if defined(USE_SELECT) || defined(USE_SELECT_WIN32)
75 /* Limited by design */
76 # define SQUID_MAXFD_LIMIT ((signed int)FD_SETSIZE)
78 #elif defined(USE_POLL)
79 /* Limited due to delay pools */
80 # define SQUID_MAXFD_LIMIT ((signed int)FD_SETSIZE)
82 #elif defined(USE_KQUEUE) || defined(USE_EPOLL) || defined(USE_DEVPOLL)
83 # define SQUID_FDSET_NOUSE 1
86 # error Unknown select loop model!
89 #if !HAVE_STRUCT_RUSAGE
91 * If we don't have getrusage() then we create a fake structure
92 * with only the fields Squid cares about. This just makes the
93 * source code cleaner, so we don't need lots of ifdefs in other
97 struct timeval ru_stime
;
98 struct timeval ru_utime
;
102 #endif /* !HAVE_STRUCT_RUSAGE */
107 * min() comparison may not always be provided.
108 * Squid bundles this template for when its needed.
109 * May be used on any type which provides operator '<'
113 min(A
const & lhs
, A
const & rhs
)
119 #else /* !__cplusplus */
120 /* for non-C++ we are stuck with the < and ? operator */
121 #define min(a,b) ((a) < (b) ? (a) : (b))
122 #endif /* __cplusplus */
128 * max() comparison may not always be provided.
129 * Squid bundles this template for when its needed.
130 * May be used on any type which provides operator '>'
134 max(A
const & lhs
, A
const & rhs
)
140 #else /* !__cplusplus */
141 /* for non-C++ we are stuck with the < and ? operator */
142 #define max(a,b) ((a) < (b) ? (b) : (a))
143 #endif /* __cplusplus */
147 * Common shared definition of what whitespace consists of for string tests
149 #define w_space " \t\n\r"
151 #ifndef SQUID_NONBLOCK
152 /* REQUIRED for the below logics. If they move this needs to as well */
156 #if defined(O_NONBLOCK)
158 * We used to assume O_NONBLOCK was broken on Solaris, but evidence
159 * now indicates that its fine on Solaris 8, and in fact required for
160 * properly detecting EOF on FIFOs. So now we assume that if
161 * its defined, it works correctly on all operating systems.
163 #define SQUID_NONBLOCK O_NONBLOCK
165 /** O_NDELAY is our fallback. */
166 #define SQUID_NONBLOCK O_NDELAY
171 * Signalling flags are apparently not always provided.
172 * TODO find out if these can be moved into specific OS portability files.
174 #if defined(__cplusplus)
188 #define SA_RESETHAND 0
190 #if SA_RESETHAND == 0 && defined(SA_ONESHOT)
192 #define SA_RESETHAND SA_ONESHOT
196 * com_err.h is a C header and needs explicit shielding, but not
197 * all other system headers including this care to do so.
200 #if HAVE_ET_COM_ERR_H
202 #include <et/com_err.h>
212 * Several function definitions which we provide for security and code safety.
214 #include "compat/xalloc.h"
215 #include "compat/xis.h"
216 #include "compat/xstrerror.h"
217 #include "compat/xstring.h"
218 #include "compat/xstrto.h"
221 * strtoll() is needed. Squid provides a portable definition.
223 #include "compat/strtoll.h"
227 #define memcpy(d,s,n) bcopy((s),(d),(n))
229 #define memcpy(d,s,n) memmove((d),(s),(n))
233 #if !HAVE_MEMMOVE && HAVE_BCOPY
234 #define memmove(d,s,n) bcopy((s),(d),(n))
238 * strnstr() is needed. The OS may not provide a working copy.
241 /* If strnstr exists and is usable we do so. */
242 #define squid_strnstr(a,b,c) strnstr(a,b,c)
244 /* If not we have our own copy imported from FreeBSD */
245 const char * squid_strnstr(const char *s
, const char *find
, size_t slen
);
249 #if !defined(PRINTF_FORMAT_ARG1)
250 #define PRINTF_FORMAT_ARG1 __attribute__ ((format (printf, 1, 2)))
252 #if !defined(PRINTF_FORMAT_ARG2)
253 #define PRINTF_FORMAT_ARG2 __attribute__ ((format (printf, 2, 3)))
255 #if !defined(PRINTF_FORMAT_ARG3)
256 #define PRINTF_FORMAT_ARG3 __attribute__ ((format (printf, 3, 4)))
259 #define PRINTF_FORMAT_ARG1
260 #define PRINTF_FORMAT_ARG2
261 #define PRINTF_FORMAT_ARG3
264 #endif /* _SQUID_COMPAT_SHARED_H */