]>
git.ipfire.org Git - thirdparty/squid.git/blob - compat/compat_shared.h
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef _SQUID_COMPAT_SHARED_H
10 #define _SQUID_COMPAT_SHARED_H
13 * This file contains all the compatibility and portability hacks
14 * Which are general-case and shared between all OS and support programs.
16 * If an OS-specific hack is needed there are per-OS files for that in
17 * the os/ sub-directory here.
19 * These hacks should be platform and location agnostic.
20 * A quick look-over of the code already here should give you an idea
21 * of the requirements for wrapping your hack for safe portability.
26 * Define an error display handler override.
27 * If error_notify is set by the linked program it will be used by the local
28 * portability functions. Otherwise perror() will be used.
30 extern void (*failure_notify
) (const char *);
34 * sys/resource.h and sys/time.h are apparently order-dependant.
39 #if HAVE_SYS_RESOURCE_H
40 #include <sys/resource.h> /* needs sys/time.h above it */
44 * DIRENT functionality can apparently come from many places.
45 * With various complaints by different compilers
49 #define NAMLEN(dirent) strlen((dirent)->d_name)
50 #else /* if not HAVE_DIRENT_H */
52 #define NAMLEN(dirent) (dirent)->d_namlen
55 #endif /* HAVE_SYS_NDIR_H */
58 #endif /* HAVE_SYS_DIR_H */
61 #endif /* HAVE_NDIR_H */
62 #endif /* HAVE_DIRENT_H */
64 /* The structure dirent also varies between 64-bit and 32-bit environments.
65 * Define our own dirent_t type for consistent simple internal use.
66 * NP: GCC seems not to care about the type naming differences.
68 #if defined(__USE_FILE_OFFSET64) && !defined(__GNUC__)
69 #define dirent_t struct dirent64
71 #define dirent_t struct dirent
75 * Filedescriptor limits in the different select loops
77 * NP: FreeBSD 7 defines FD_SETSIZE as unsigned but Squid needs
78 * it to be signed to compare it with signed values.
79 * Linux and others including FreeBSD <7, define it as signed.
80 * If this causes any issues please contact squid-dev@squid-cache.org
82 #if defined(USE_SELECT) || defined(USE_SELECT_WIN32)
83 /* Limited by design */
84 # define SQUID_MAXFD_LIMIT ((signed int)FD_SETSIZE)
86 #elif defined(USE_POLL)
87 /* Limited due to delay pools */
88 # define SQUID_MAXFD_LIMIT ((signed int)FD_SETSIZE)
90 #elif defined(USE_KQUEUE) || defined(USE_EPOLL) || defined(USE_DEVPOLL)
91 # define SQUID_FDSET_NOUSE 1
94 # error Unknown select loop model!
97 #if !HAVE_STRUCT_RUSAGE
99 * If we don't have getrusage() then we create a fake structure
100 * with only the fields Squid cares about. This just makes the
101 * source code cleaner, so we don't need lots of ifdefs in other
105 struct timeval ru_stime
;
106 struct timeval ru_utime
;
110 #endif /* !HAVE_STRUCT_RUSAGE */
115 * min() comparison may not always be provided.
116 * Squid bundles this template for when its needed.
117 * May be used on any type which provides operator '<'
121 min(A
const & lhs
, A
const & rhs
)
127 #else /* !__cplusplus */
128 /* for non-C++ we are stuck with the < and ? operator */
129 #define min(a,b) ((a) < (b) ? (a) : (b))
130 #endif /* __cplusplus */
136 * max() comparison may not always be provided.
137 * Squid bundles this template for when its needed.
138 * May be used on any type which provides operator '>'
142 max(A
const & lhs
, A
const & rhs
)
148 #else /* !__cplusplus */
149 /* for non-C++ we are stuck with the < and ? operator */
150 #define max(a,b) ((a) < (b) ? (b) : (a))
151 #endif /* __cplusplus */
155 * Common shared definition of what whitespace consists of for string tests
157 #define w_space " \t\n\r"
159 #ifndef SQUID_NONBLOCK
160 /* REQUIRED for the below logics. If they move this needs to as well */
164 #if defined(O_NONBLOCK)
166 * We used to assume O_NONBLOCK was broken on Solaris, but evidence
167 * now indicates that its fine on Solaris 8, and in fact required for
168 * properly detecting EOF on FIFOs. So now we assume that if
169 * its defined, it works correctly on all operating systems.
171 #define SQUID_NONBLOCK O_NONBLOCK
173 /** O_NDELAY is our fallback. */
174 #define SQUID_NONBLOCK O_NDELAY
179 * Signalling flags are apparently not always provided.
180 * TODO find out if these can be moved into specific OS portability files.
182 #if defined(__cplusplus)
196 #define SA_RESETHAND 0
198 #if SA_RESETHAND == 0 && defined(SA_ONESHOT)
200 #define SA_RESETHAND SA_ONESHOT
204 * com_err.h is a C header and needs explicit shielding, but not
205 * all other system headers including this care to do so.
208 #if HAVE_ET_COM_ERR_H
210 #include <et/com_err.h>
220 * Several function definitions which we provide for security and code safety.
222 #include "compat/xalloc.h"
223 #include "compat/xis.h"
224 #include "compat/xstrerror.h"
225 #include "compat/xstring.h"
226 #include "compat/xstrto.h"
229 * strtoll() is needed. Squid provides a portable definition.
231 #include "compat/strtoll.h"
233 // memrchr() is a GNU extension. MinGW in particular does not define it.
234 #include "compat/memrchr.h"
238 #define memcpy(d,s,n) bcopy((s),(d),(n))
240 #define memcpy(d,s,n) memmove((d),(s),(n))
244 #if !HAVE_MEMMOVE && HAVE_BCOPY
245 #define memmove(d,s,n) bcopy((s),(d),(n))
249 * strnstr() is needed. The OS may not provide a working copy.
252 /* If strnstr exists and is usable we do so. */
253 #define squid_strnstr(a,b,c) strnstr(a,b,c)
255 /* If not we have our own copy imported from FreeBSD */
256 const char * squid_strnstr(const char *s
, const char *find
, size_t slen
);
260 #if !defined(PRINTF_FORMAT_ARG1)
261 #define PRINTF_FORMAT_ARG1 __attribute__ ((format (printf, 1, 2)))
263 #if !defined(PRINTF_FORMAT_ARG2)
264 #define PRINTF_FORMAT_ARG2 __attribute__ ((format (printf, 2, 3)))
266 #if !defined(PRINTF_FORMAT_ARG3)
267 #define PRINTF_FORMAT_ARG3 __attribute__ ((format (printf, 3, 4)))
270 #define PRINTF_FORMAT_ARG1
271 #define PRINTF_FORMAT_ARG2
272 #define PRINTF_FORMAT_ARG3
275 #endif /* _SQUID_COMPAT_SHARED_H */