diff options
author | Christian Grothoff <christian@grothoff.org> | 2008-08-30 05:07:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2008-08-30 05:07:59 +0000 |
commit | bcfe4eab193937246a0578a3b90da6b3ebea56af (patch) | |
tree | 22434d04219504e615859ad9d712113d21a6df9b | |
parent | 213806696d374400835b9475e4ad519370d3e09d (diff) | |
download | libmicrohttpd-bcfe4eab193937246a0578a3b90da6b3ebea56af.tar.gz libmicrohttpd-bcfe4eab193937246a0578a3b90da6b3ebea56af.zip |
ac
-rw-r--r-- | src/daemon/https/lgl/memmem.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/daemon/https/lgl/memmem.c b/src/daemon/https/lgl/memmem.c new file mode 100644 index 00000000..9a0e67d2 --- /dev/null +++ b/src/daemon/https/lgl/memmem.c | |||
@@ -0,0 +1,61 @@ | |||
1 | /* Copyright (C) 1991,92,93,94,96,97,98,2000,2004,2007 Free Software Foundation, Inc. | ||
2 | This file is part of the GNU C Library. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU Lesser General Public License as published by | ||
6 | the Free Software Foundation; either version 2.1, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | #ifndef _LIBC | ||
19 | #include "MHD_config.h" | ||
20 | #endif | ||
21 | |||
22 | #include <stddef.h> | ||
23 | #include <string.h> | ||
24 | |||
25 | #ifndef _LIBC | ||
26 | # define __builtin_expect(expr, val) (expr) | ||
27 | #endif | ||
28 | |||
29 | #undef memmem | ||
30 | |||
31 | /* Return the first occurrence of NEEDLE in HAYSTACK. */ | ||
32 | void * | ||
33 | memmem (haystack, haystack_len, needle, needle_len) | ||
34 | const void *haystack; | ||
35 | size_t haystack_len; | ||
36 | const void *needle; | ||
37 | size_t needle_len; | ||
38 | { | ||
39 | const char *begin; | ||
40 | const char *const last_possible = (const char *) haystack + haystack_len | ||
41 | - needle_len; | ||
42 | |||
43 | if (needle_len == 0) | ||
44 | /* The first occurrence of the empty string is deemed to occur at | ||
45 | the beginning of the string. */ | ||
46 | return (void *) haystack; | ||
47 | |||
48 | /* Sanity check, otherwise the loop might search through the whole | ||
49 | memory. */ | ||
50 | if (__builtin_expect (haystack_len < needle_len, 0)) | ||
51 | return NULL; | ||
52 | |||
53 | for (begin = (const char *) haystack; begin <= last_possible; ++begin) | ||
54 | if (begin[0] == ((const char *) needle)[0] | ||
55 | && !memcmp ((const void *) &begin[1], | ||
56 | (const void *) ((const char *) needle + 1), | ||
57 | needle_len - 1)) | ||
58 | return (void *) begin; | ||
59 | |||
60 | return NULL; | ||
61 | } | ||