From: Amos Jeffries Date: Fri, 19 Sep 2014 17:52:22 +0000 (-0700) Subject: Portability: add shim for memrchr() and detect direct.h X-Git-Tag: SQUID_3_5_0_1~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee4d4e85f792eedfa274aebc9ce2d02866d6be2b;p=thirdparty%2Fsquid.git Portability: add shim for memrchr() and detect direct.h Windows requires direct.h to define the chdir(), chroot(), cwd() and related system calls. memrchr() is not always defined but required by SBuf. Provide a local implementation for systems that need it. --- diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c36a101818..1a2749cb91 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -284,6 +284,7 @@ Thank you! Thomas-Martin Seck Tianyin Xu Tim Starling + Todd C. Miller Tomas Hozza Tony Lorimer Unknown - NetBSD Project diff --git a/CREDITS b/CREDITS index 690b2f54ff..91f3ca8141 100644 --- a/CREDITS +++ b/CREDITS @@ -465,6 +465,25 @@ compat/inet_pton.c: ============================================================================== +compat/memrchr.cc, +compat/memrchr.h: + + * Copyright (c) 2007 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +============================================================================== + compat/strtoll.c: /*- diff --git a/compat/Makefile.am b/compat/Makefile.am index 1c70b143df..bde70b54d8 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -38,6 +38,8 @@ libcompat_squid_la_SOURCES = \ inet_ntop.h \ inet_pton.h \ initgroups.h \ + memrchr.cc \ + memrchr.h \ osdetect.h \ psignal.h \ shm.cc \ diff --git a/compat/compat_shared.h b/compat/compat_shared.h index b64c9e7be4..70e571ae58 100644 --- a/compat/compat_shared.h +++ b/compat/compat_shared.h @@ -230,6 +230,9 @@ extern "C" { */ #include "compat/strtoll.h" +// memrchr() is a GNU extension. MinGW in particular does not define it. +#include "compat/memrchr.h" + #if !HAVE_MEMCPY #if HAVE_BCOPY #define memcpy(d,s,n) bcopy((s),(d),(n)) diff --git a/compat/memrchr.cc b/compat/memrchr.cc new file mode 100644 index 0000000000..491e13b680 --- /dev/null +++ b/compat/memrchr.cc @@ -0,0 +1,50 @@ +/* + * Copyright (C) 1996-2014 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +/* + * Copyright (c) 2007 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "squid.h" + +#if !HAVE_MEMRCHR + +#include "compat/memrchr.h" + +/* + * Reverse memchr() + * Find the last occurrence of 'c' in the buffer 's' of size 'n'. + */ +void * +memrchr(const void *s, int c, size_t n) +{ + const unsigned char *cp; + + if (n != 0) { + cp = (unsigned char *)s + n; + do { + if (*(--cp) == (unsigned char)c) + return((void *)cp); + } while (--n != 0); + } + return((void *)0); +} + +#endif diff --git a/compat/memrchr.h b/compat/memrchr.h new file mode 100644 index 0000000000..9b3c1d8566 --- /dev/null +++ b/compat/memrchr.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 1996-2014 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +/* + * Copyright (c) 2007 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef SQUID_COMPAT_MEMRCHR_H +#define SQUID_COMPAT_MEMRCHR_H + +#if !HAVE_MEMRCHR + +/** + * Reverse memchr() + * Find the last occurrence of 'c' in the buffer 's' of size 'n'. + */ +void *memrchr(const void *s, int c, size_t n); + +#endif +#endif /* SQUID_COMPAT_MEMRCHR_H */ diff --git a/compat/os/mswindows.h b/compat/os/mswindows.h index 503885e205..ff06137af2 100644 --- a/compat/os/mswindows.h +++ b/compat/os/mswindows.h @@ -32,6 +32,9 @@ #endif #endif /* _SQUID_MINGW_ */ +#if HAVE_DIRECT_H +#include +#endif #if HAVE_FCNTL_H #include #endif /* HAVE_FCNTL_H */ @@ -97,7 +100,6 @@ typedef unsigned long ino_t; #define fstat _fstati64 #define lseek _lseeki64 #define memccpy _memccpy -#define mkdir(p,F) _mkdir((p)) #define mktemp _mktemp #define snprintf _snprintf #define stat _stati64 @@ -108,26 +110,22 @@ typedef unsigned long ino_t; #define vsnprintf _vsnprintf #endif -/* CygWin and MinGW compilers need these. Microsoft C Compiler does not. */ -#if _SQUID_MINGW_ || _SQUID_CYGWIN_ -#define mkdir(p,F) mkdir((p)) -#endif - /* Microsoft C Compiler and CygWin need these. MinGW does not */ #if defined(_MSC_VER) || _SQUID_CYGWIN_ SQUIDCEXTERN int WIN32_ftruncate(int fd, off_t size); #define ftruncate WIN32_ftruncate SQUIDCEXTERN int WIN32_truncate(const char *pathname, off_t length); #define truncate WIN32_truncate +#define chdir _chdir #endif /* All three compiler systems need these: */ -#define chdir _chdir #define dup _dup #define dup2 _dup2 #define fdopen _fdopen #define getcwd _getcwd #define getpid _getpid +#define mkdir(p,F) mkdir((p)) #define pclose _pclose #define popen _popen #define putenv _putenv diff --git a/configure.ac b/configure.ac index 9479f510f4..87ce88bb09 100644 --- a/configure.ac +++ b/configure.ac @@ -2744,6 +2744,7 @@ AC_CHECK_HEADERS( \ bstring.h \ crypt.h \ ctype.h \ + direct.h \ errno.h \ execinfo.h \ fcntl.h \ @@ -3329,6 +3330,7 @@ AC_CHECK_FUNCS(\ mallopt \ memcpy \ memmove \ + memrchr \ memset \ mkstemp \ mktime \