Permalink
Switch branches/tags
aj/revert-sunrpc aj/shared-linux-fcntl allan/config-files andros/avx512f-mem andros/libmvec andros/pr19654 archlinux/2.18/master azanella/bz12683 carlos/dlmopen carlos/master cmetcalf/tile-2.15 cvs/fedora-2_3-branch cvs/fedora-2_5-branch cvs/fedora-branch cvs/glibc-2-1-branch cvs/glibc-2-2-branch cvs/glibc-2_0_x cvs/glibc-2_3-branch cvs/glibc-2_5-branch cvs/glibc-2_6-branch cvs/glibc-2_7-branch cvs/glibc-2_8-branch cvs/glibc-2_9-branch cvs/glibc-2_10-branch cvs/master cvs/sparc-2_0_x-branch cvs/thomas-posix1996 davem/sparc dj/malloc fedora/master fedora/2.10/master fedora/2.11/master fedora/2.12/master fedora/2.13/master fedora/2.14/master fedora/2.22/master fw/extend_alloca gentoo/2.18 gentoo/2.19 gentoo/2.20 gentoo/2.21 gentoo/2.22 gentoo/2.23 hjl/avx128 hjl/avx512f-mem/master hjl/avx512f-mem/old hjl/avx512f-mem/prefetcht1 hjl/cpuid/master hjl/cpuid/2.21 hjl/cpuid/2.22 hjl/ctor/release/2.11 hjl/ctor/release/2.12 hjl/erms/i386 hjl/erms/ifunc hjl/erms/master hjl/erms/nt hjl/erms/2.22 hjl/erms/2.23 hjl/fma/master hjl/global hjl/gold hjl/i386/master hjl/i486/multiarch-old hjl/i486/multiarch hjl/implies hjl/init hjl/ld.so/master hjl/memcpy/dpdk/master hjl/mempcpy hjl/plt/master hjl/plt/2.21 hjl/plt/2.22 hjl/pr13862 hjl/pr14370 hjl/pr14562/master hjl/pr14562/2.16 hjl/pr14654 hjl/pr14716 hjl/pr14831 hjl/pr14937 hjl/pr14941 hjl/pr14955 hjl/pr14995 hjl/pr17711/2.18 hjl/pr17711/2.19 hjl/pr17711/2.20 hjl/pr17711/2.21 hjl/pr17841/master hjl/pr17841/2.21 hjl/pr18078 hjl/pr18422 hjl/pr18661 hjl/pr18696 hjl/pr18858/master hjl/pr19122 hjl/pr19178/master hjl/pr19363/clobber hjl/pr19363/master hjl/pr19363/2.22 hjl/pr19371/master hjl/pr19463 hjl/pr19583 hjl/pr19590 hjl/pr19679/2.23 hjl/pr19776/master hjl/pthread/2.21 hjl/pthread/2.22 hjl/release/2.20/master hjl/secondary/master hjl/secondary/2.21 hjl/size/master hjl/tst-plt hjl/unaligned hjl/x32/master hjl/x32/release/2.12 hjl/x32/release/2.15 hjl/x86 hjl/32bit/master hjl/32bit/2.22 ibm/master ibm/2.8/master ibm/2.10/master ibm/2.11/master ibm/2.12/master ibm/2.13/master ibm/2.16/master ibm/2.18/master ibm/2.19/master ibm/2.20/master ibm/2.22/master ldmitrie/intel_mpx linaro/master lxoliva/getaddrinfo master neleai/string-x64 neleai/strlen origin/ibm/2.8/master pasky/fixes-overdue pasky/fixes release/2.10/master release/2.11/master release/2.12/master release/2.13/master release/2.14/master release/2.15/master release/2.16/master release/2.17/master release/2.18/master release/2.19/master release/2.20/master release/2.21/master release/2.22/master release/2.23/master roland/Wshadow roland/add-on-abi-tags roland/backtrace-syms roland/cancelhandling roland/disable-nis roland/getpid roland/gold-vs-libc roland/hwcap_mask roland/manual-check roland/nacl-debug-hack roland/nacl-exit-stacks roland/nacl-port/master roland/nptl_db roland/pthread_attr_getstack roland/stat64 roland/sysconf-clocks roland/tempname roland/x86_64-crt1-cfi rsa/hwcap2_v3 rsa/hwcap2_v4 rsa/hwcap2_v5 rsa/hwcap2_v6 rsa/power8_partial rsa/power8 rsa/stdint_headers rsa/stdint_noheaders rsa/stdint rsa/2.17_backports_v2 rsa/2.17_backports_v3 rsa/2.17_backports rth/aa-memset rth/aa-opt rth/execl rth/tramp siddhesh/is_in_module siddhesh/mmap-fallback siddhesh/posix-wundef siddhesh/sem_timedwait siddhesh/tunables tuliom/multilib
Nothing to show
Find file Copy path
f7a9f78 Jan 5, 2016
0 contributors

Users who have contributed to this file

93 lines (76 sloc) 3.11 KB
/* Return the offset of one string within another.
Copyright (C) 1994-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* This particular implementation was written by Eric Blake, 2008. */
#ifndef _LIBC
# include <config.h>
#endif
/* Specification of strstr. */
#include <string.h>
#include <stdbool.h>
#ifndef _LIBC
# define __builtin_expect(expr, val) (expr)
#endif
#define RETURN_TYPE char *
#define AVAILABLE(h, h_l, j, n_l) \
(!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
&& ((h_l) = (j) + (n_l)))
#define CHECK_EOL (1)
#define RET0_IF_0(a) if (!a) goto ret0
#include "str-two-way.h"
#undef strstr
#ifndef STRSTR
#define STRSTR strstr
#endif
/* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK
if NEEDLE is empty, otherwise NULL if NEEDLE is not found in
HAYSTACK. */
char *
STRSTR (const char *haystack_start, const char *needle_start)
{
const char *haystack = haystack_start;
const char *needle = needle_start;
size_t needle_len; /* Length of NEEDLE. */
size_t haystack_len; /* Known minimum length of HAYSTACK. */
bool ok = true; /* True if NEEDLE is prefix of HAYSTACK. */
/* Determine length of NEEDLE, and in the process, make sure
HAYSTACK is at least as long (no point processing all of a long
NEEDLE if HAYSTACK is too short). */
while (*haystack && *needle)
ok &= *haystack++ == *needle++;
if (*needle)
return NULL;
if (ok)
return (char *) haystack_start;
/* Reduce the size of haystack using strchr, since it has a smaller
linear coefficient than the Two-Way algorithm. */
needle_len = needle - needle_start;
haystack = strchr (haystack_start + 1, *needle_start);
if (!haystack || __builtin_expect (needle_len == 1, 0))
return (char *) haystack;
needle -= needle_len;
haystack_len = (haystack > haystack_start + needle_len ? 1
: needle_len + haystack_start - haystack);
/* Perform the search. Abstract memory is considered to be an array
of 'unsigned char' values, not an array of 'char' values. See
ISO C 99 section 6.2.6.1. */
if (needle_len < LONG_NEEDLE_THRESHOLD)
return two_way_short_needle ((const unsigned char *) haystack,
haystack_len,
(const unsigned char *) needle, needle_len);
return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
(const unsigned char *) needle, needle_len);
}
libc_hidden_builtin_def (strstr)
#undef LONG_NEEDLE_THRESHOLD