Back to index

glibc  2.9
Functions
wmemchr.c File Reference
#include <wchar.h>

Go to the source code of this file.

Functions

wchar_t * wmemchr (const wchar_t *s, wchar_t c, size_t n)

Function Documentation

wchar_t* wmemchr ( const wchar_t *  s,
wchar_t  c,
size_t  n 
)

Definition at line 23 of file wmemchr.c.

{
  /* For performance reasons unfold the loop four times.  */
  while (n >= 4)
    {
      if (s[0] == c)
       return (wchar_t *) s;
      if (s[1] == c)
       return (wchar_t *) &s[1];
      if (s[2] == c)
       return (wchar_t *) &s[2];
      if (s[3] == c)
       return (wchar_t *) &s[3];
      s += 4;
      n -= 4;
    }

  if (n > 0)
    {
      if (*s == c)
       return (wchar_t *) s;
      ++s;
      --n;
    }
  if (n > 0)
    {
      if (*s == c)
       return (wchar_t *) s;
      ++s;
      --n;
    }
  if (n > 0)
    if (*s == c)
      return (wchar_t *) s;

  return NULL;
}