root/include/asm-ppc/string.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. memset
  2. strstr

   1 #ifndef _PPC_STRING_H_
   2 #define _PPC_STRING_H_
   3 
   4 
   5 
   6 /*
   7  * keep things happy, the compile became unhappy since memset is
   8  * in include/string.h and lib/string.c with different args
   9  *                          -- Cort
  10  */
  11 
  12 #define  __HAVE_ARCH_MEMSET
  13 extern inline void * memset(void * s,int c,size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
  14 {
  15         char *xs = (char *) s;
  16 
  17         while (count--)
  18                 *xs++ = c;
  19 
  20         return s;
  21 }
  22 #define __HAVE_ARCH_STRSTR
  23 /* Return the first ocurrence of NEEDLE in HAYSTACK.  */
  24 extern inline char *
  25 strstr(const char *haystack, const char *needle)
     /* [previous][next][first][last][top][bottom][index][help] */
  26 {
  27   const char *const needle_end = strchr(needle, '\0');
  28   const char *const haystack_end = strchr(haystack, '\0');
  29   const size_t needle_len = needle_end - needle;
  30   const size_t needle_last = needle_len - 1;
  31   const char *begin;
  32 
  33   if (needle_len == 0)
  34 #ifdef __linux__
  35     return (char *) haystack;
  36 #else
  37     return (char *) haystack_end;
  38 #endif
  39   if ((size_t) (haystack_end - haystack) < needle_len)
  40     return NULL;
  41 
  42   for (begin = &haystack[needle_last]; begin < haystack_end; ++begin)
  43     {
  44       register const char *n = &needle[needle_last];
  45       register const char *h = begin;
  46 
  47       do
  48         if (*h != *n)
  49           goto loop;            /* continue for loop */
  50       while (--n >= needle && --h >= haystack);
  51 
  52       return (char *) h;
  53 
  54     loop:;
  55     }
  56 
  57   return NULL;
  58 }
  59 
  60 
  61 
  62 #endif

/* [previous][next][first][last][top][bottom][index][help] */