]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Portability: add shim for memrchr() and detect direct.h
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 19 Sep 2014 17:52:22 +0000 (10:52 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 19 Sep 2014 17:52:22 +0000 (10:52 -0700)
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.

CONTRIBUTORS
CREDITS
compat/Makefile.am
compat/compat_shared.h
compat/memrchr.cc [new file with mode: 0644]
compat/memrchr.h [new file with mode: 0644]
compat/os/mswindows.h
configure.ac

index c36a101818f2ed47a67b8b8e1b37043d36dfb4d7..1a2749cb9106e164bf4134d67eb7346dc7c90abf 100644 (file)
@@ -284,6 +284,7 @@ Thank you!
     Thomas-Martin Seck <tmseck@netcologne.de>
     Tianyin Xu <tixu@cs.ucsd.edu>
     Tim Starling <tstarling@wikimedia.org>
+    Todd C. Miller <Todd.Miller@courtesan.com>
     Tomas Hozza <thozza@redhat.com>
     Tony Lorimer <tlorimer@au.mdis.com>
     Unknown - NetBSD Project
diff --git a/CREDITS b/CREDITS
index 690b2f54fffef2742dabfcc8f9c5d43476eb6e81..91f3ca8141f3d835938b4a63ab1888e2f3fb3d31 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -465,6 +465,25 @@ compat/inet_pton.c:
 
 ==============================================================================
 
+compat/memrchr.cc,
+compat/memrchr.h:
+
+ * Copyright (c) 2007 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * 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:
 
 /*-
index 1c70b143dfeaa3ce02ea4fb30d6131f89e4fd55b..bde70b54d8ecf4f700c409f8593618f3f5f47003 100644 (file)
@@ -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 \
index b64c9e7be430d7a10411a1f3498fbf5d52b66dcb..70e571ae585412260a5ebaac56881f243ebf0ab2 100644 (file)
@@ -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 (file)
index 0000000..491e13b
--- /dev/null
@@ -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 <Todd.Miller@courtesan.com>
+ *
+ * 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 (file)
index 0000000..9b3c1d8
--- /dev/null
@@ -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 <Todd.Miller@courtesan.com>
+ *
+ * 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 */
index 503885e205a60a8990544b48e928820456a380a2..ff06137af2f8b431b89893ebc0af6575bd7db62d 100644 (file)
@@ -32,6 +32,9 @@
 #endif
 #endif /* _SQUID_MINGW_ */
 
+#if HAVE_DIRECT_H
+#include <direct.h>
+#endif
 #if HAVE_FCNTL_H
 #include <fcntl.h>
 #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
index 9479f510f421d99dc12001b6204b69d7a3e02cd5..87ce88bb0906afae49221b27a0b2e6dc5d6ad0e5 100644 (file)
@@ -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 \