Back to index

glibc  2.9
Defines | Functions
strcasestr.c File Reference
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <strings.h>
#include "str-two-way.h"

Go to the source code of this file.

Defines

#define TOLOWER(Ch)   (isupper (Ch) ? tolower (Ch) : (Ch))
#define RETURN_TYPE   char *
#define AVAILABLE(h, h_l, j, n_l)
#define CANON_ELEMENT(c)   TOLOWER (c)
#define CMP_FUNC(p1, p2, l)   __strncasecmp ((const char *) (p1), (const char *) (p2), l)

Functions

char * __strcasestr (const char *haystack_start, const char *needle_start)

Define Documentation

#define AVAILABLE (   h,
  h_l,
  j,
  n_l 
)
Value:
(!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l))       \
   && ((h_l) = (j) + (n_l)))

Definition at line 44 of file strcasestr.c.

#define CANON_ELEMENT (   c)    TOLOWER (c)

Definition at line 47 of file strcasestr.c.

#define CMP_FUNC (   p1,
  p2,
  l 
)    __strncasecmp ((const char *) (p1), (const char *) (p2), l)

Definition at line 48 of file strcasestr.c.

#define RETURN_TYPE   char *

Definition at line 43 of file strcasestr.c.

#define TOLOWER (   Ch)    (isupper (Ch) ? tolower (Ch) : (Ch))

Definition at line 40 of file strcasestr.c.


Function Documentation

char* __strcasestr ( const char *  haystack_start,
const char *  needle_start 
)

Definition at line 59 of file strcasestr.c.

{
  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 &= (TOLOWER ((unsigned char) *haystack)
            == TOLOWER ((unsigned char) *needle));
      haystack++;
      needle++;
    }
  if (*needle)
    return NULL;
  if (ok)
    return (char *) haystack_start;
  needle_len = needle - needle_start;
  haystack = haystack_start + 1;
  haystack_len = needle_len - 1;

  /* 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_start,
                             needle_len);
  return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
                           (const unsigned char *) needle_start,
                           needle_len);
}

Here is the call graph for this function: