------------------------------------------------------------ revno: 13596 revision-id: squid3@treenet.co.nz-20140919175222-2mbiktru032gvb9s parent: squid3@treenet.co.nz-20140917132107-qegw7ryzw84878bk committer: Amos Jeffries branch nick: trunk timestamp: Fri 2014-09-19 10:52:22 -0700 message: 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. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140919175222-2mbiktru032gvb9s # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 5ca664d2fdda48dccb34d840c74e723c74440172 # timestamp: 2014-09-25 05:53:35 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20140917132107-\ # qegw7ryzw84878bk # # Begin patch === modified file 'CONTRIBUTORS' --- CONTRIBUTORS 2014-09-14 12:10:55 +0000 +++ CONTRIBUTORS 2014-09-19 17:52:22 +0000 @@ -284,6 +284,7 @@ Thomas-Martin Seck Tianyin Xu Tim Starling + Todd C. Miller Tomas Hozza Tony Lorimer Unknown - NetBSD Project === modified file 'CREDITS' --- CREDITS 2014-09-13 15:04:00 +0000 +++ CREDITS 2014-09-19 17:52:22 +0000 @@ -465,6 +465,25 @@ ============================================================================== +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: /*- === modified file 'compat/Makefile.am' --- compat/Makefile.am 2014-09-02 01:08:58 +0000 +++ compat/Makefile.am 2014-09-19 17:52:22 +0000 @@ -38,6 +38,8 @@ inet_ntop.h \ inet_pton.h \ initgroups.h \ + memrchr.cc \ + memrchr.h \ osdetect.h \ psignal.h \ shm.cc \ === modified file 'compat/compat_shared.h' --- compat/compat_shared.h 2014-09-02 01:08:58 +0000 +++ compat/compat_shared.h 2014-09-19 17:52:22 +0000 @@ -230,6 +230,9 @@ */ #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)) === added file 'compat/memrchr.cc' --- compat/memrchr.cc 1970-01-01 00:00:00 +0000 +++ compat/memrchr.cc 2014-09-19 17:52:22 +0000 @@ -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 === added file 'compat/memrchr.h' --- compat/memrchr.h 1970-01-01 00:00:00 +0000 +++ compat/memrchr.h 2014-09-19 17:52:22 +0000 @@ -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 */ === modified file 'compat/os/mswindows.h' --- compat/os/mswindows.h 2014-09-15 00:53:05 +0000 +++ compat/os/mswindows.h 2014-09-19 17:52:22 +0000 @@ -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 @@ #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 @@ #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 === modified file 'configure.ac' --- configure.ac 2014-09-17 13:21:07 +0000 +++ configure.ac 2014-09-19 17:52:22 +0000 @@ -2744,6 +2744,7 @@ bstring.h \ crypt.h \ ctype.h \ + direct.h \ errno.h \ execinfo.h \ fcntl.h \ @@ -3329,6 +3330,7 @@ mallopt \ memcpy \ memmove \ + memrchr \ memset \ mkstemp \ mktime \