OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [string/] [strncmp.c] - Diff between revs 39 and 56

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 39 Rev 56
Line 62... Line 62...
_DEFUN (strncmp, (s1, s2, n),
_DEFUN (strncmp, (s1, s2, n),
        _CONST char *s1 _AND
        _CONST char *s1 _AND
        _CONST char *s2 _AND
        _CONST char *s2 _AND
        size_t n)
        size_t n)
{
{
#ifdef PREFER_SIZE_OVER_SPEED
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
  if (n == 0)
  if (n == 0)
    return 0;
    return 0;
 
 
  while (n-- != 0 && *s1 == *s2)
  while (n-- != 0 && *s1 == *s2)
    {
    {
      if (n == 0 || *s1 == '\0' || *s2 == '\0')
      if (n == 0 || *s1 == '\0')
        break;
        break;
      s1++;
      s1++;
      s2++;
      s2++;
    }
    }
 
 
Line 83... Line 83...
 
 
  if (n == 0)
  if (n == 0)
    return 0;
    return 0;
 
 
  /* If s1 or s2 are unaligned, then compare bytes. */
  /* If s1 or s2 are unaligned, then compare bytes. */
  if (UNALIGNED (s1, s2))
  if (!UNALIGNED (s1, s2))
    {
 
      while (n-- != 0 && *s1 == *s2)
 
        {
        {
          /* If we've run out of bytes or hit a null, return zero
 
             since we already know *s1 == *s2.  */
 
          if (n == 0 || *s1 == '\0')
 
            return 0;
 
          s1++;
 
          s2++;
 
        }
 
      return (*(unsigned char *) s1) - (*(unsigned char *) s2);
 
    }
 
 
 
  /* If s1 and s2 are word-aligned, compare them a word at a time. */
  /* If s1 and s2 are word-aligned, compare them a word at a time. */
  a1 = (unsigned long*)s1;
  a1 = (unsigned long*)s1;
  a2 = (unsigned long*)s2;
  a2 = (unsigned long*)s2;
  while (n >= sizeof (long) && *a1 == *a2)
  while (n >= sizeof (long) && *a1 == *a2)
    {
    {
Line 116... Line 104...
    }
    }
 
 
  /* A difference was detected in last few bytes of s1, so search bytewise */
  /* A difference was detected in last few bytes of s1, so search bytewise */
  s1 = (char*)a1;
  s1 = (char*)a1;
  s2 = (char*)a2;
  s2 = (char*)a2;
 
    }
 
 
  while (n-- > 0 && *s1 == *s2)
  while (n-- > 0 && *s1 == *s2)
    {
    {
      /* If we've run out of bytes or hit a null, return zero
      /* If we've run out of bytes or hit a null, return zero
         since we already know *s1 == *s2.  */
         since we already know *s1 == *s2.  */

powered by: WebSVN 2.1.0

© copyright 1999-2026 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.