diff options
author | Adam Chlipala <adamc@csail.mit.edu> | 2018-11-25 15:42:12 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-25 15:42:12 -0500 |
commit | bb8209c854404d2eb231c878134b13f15f22410d (patch) | |
tree | cd73d7eea5432f111d04a4d182c839bf1a8c01c4 | |
parent | 096fbda34b67cccd2026c44006bd9bc98d28c98c (diff) | |
parent | 765c39bea005eaa49852ac1f877ed042ab5b68e6 (diff) |
Merge pull request #147 from bbarenblat/master
Use our own memmem only when libc doesn’t have one
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/c/memmem.c | 15 | ||||
-rw-r--r-- | src/c/memmem.h | 23 | ||||
-rw-r--r-- | src/c/request.c | 5 |
4 files changed, 33 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac index 54eac40e..75bba230 100644 --- a/configure.ac +++ b/configure.ac @@ -111,6 +111,8 @@ pthread_t a; AC_MSG_RESULT(yes), AC_MSG_RESULT(no)) +AC_CHECK_FUNCS_ONCE([memmem]) + AC_SUBST(CC) AC_SUBST(BIN) AC_SUBST(LIB) diff --git a/src/c/memmem.c b/src/c/memmem.c index f31f4e31..efddd0c1 100644 --- a/src/c/memmem.c +++ b/src/c/memmem.c @@ -1,4 +1,6 @@ -#include "config.h" +#include "memmem.h" + +#ifndef HAVE_MEMMEM /* $NetBSD$ */ @@ -38,8 +40,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -// Function renamed by Adam Chlipala in 2016. - #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) __RCSID("$NetBSD$"); @@ -54,13 +54,8 @@ __RCSID("$NetBSD$"); #define NULL ((char *)0) #endif -/* - * urweb_memmem() returns the location of the first occurence of data - * pattern b2 of size len2 in memory block b1 of size len1 or - * NULL if none is found. - */ void * -urweb_memmem(const void *b1, size_t len1, const void *b2, size_t len2) +memmem(const void *b1, size_t len1, const void *b2, size_t len2) { /* Sanity check */ if(!(b1 != NULL && b2 != NULL && len1 != 0 && len2 != 0)) @@ -85,3 +80,5 @@ urweb_memmem(const void *b1, size_t len1, const void *b2, size_t len2) return NULL; } + +#endif // !defined(HAVE_MEMMEM) diff --git a/src/c/memmem.h b/src/c/memmem.h new file mode 100644 index 00000000..0ddbb494 --- /dev/null +++ b/src/c/memmem.h @@ -0,0 +1,23 @@ +#ifndef URWEB_MEMMEM_H +#define URWEB_MEMMEM_H + +#include "config.h" + +#ifdef HAVE_MEMMEM + +#include <string.h> + +#else // !defined(HAVE_MEMMEM) + +#include <stddef.h> + +/* + * memmem() returns the location of the first occurence of data + * pattern b2 of size len2 in memory block b1 of size len1 or + * NULL if none is found. + */ +void *memmem(const void *b1, size_t len1, const void *b2, size_t len2); + +#endif // !defined(HAVE_MEMMEM) + +#endif // URWEB_MEMMEM_H diff --git a/src/c/request.c b/src/c/request.c index 3e7ac34c..195b3cdc 100644 --- a/src/c/request.c +++ b/src/c/request.c @@ -11,13 +11,12 @@ #include <pthread.h> +#include "memmem.h" #include "urweb.h" #include "request.h" #define MAX_RETRIES 5 -void *urweb_memmem(const void *b1, size_t len1, const void *b2, size_t len2); - static int try_rollback(uw_context ctx, int will_retry, void *logger_data, uw_logger log_error) { int r = uw_rollback(ctx, will_retry); @@ -422,7 +421,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx, } } - part = urweb_memmem(after_sub_headers, body + body_len - after_sub_headers, boundary, boundary_len); + part = memmem(after_sub_headers, body + body_len - after_sub_headers, boundary, boundary_len); if (!part) { log_error(logger_data, "Missing boundary after multipart payload\n"); return FAILED; |