This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strncasecmp bugfix and improvements


Thanks! I hadn't expected such a quick response! :)

Here are the other routines changed similarly. The first gets a similar performance improvement; the others are changed only to avoid passing negative values to toupper/tolower. I have _ansi'fied this time.

The docs for both strcasecmp and strncasecmp say "after both are converted to uppercase" - this is wrong, because both are converted to lowercase.

int 
_DEFUN (strcasecmp, (s1, s2, n),
        _CONST char *s1 _AND
        _CONST char *s2)
{
  _CONST unsigned char *ucs1 = (_CONST unsigned char *) s1;
  _CONST unsigned char *ucs2 = (_CONST unsigned char *) s2;
  int d = 0;
  for ( ; ; )
    {
      _CONST int c1 = tolower(*ucs1++);
      _CONST int c2 = tolower(*ucs2++);
      if (((d = c1 - c2) != 0) || (c2 == '\0'))
        break;
    }
  return d;
}

char *
_DEFUN (strlwr, (s),
        char *s)
{
  unsigned char *ucs = (unsigned char *) s;
  for ( ; *ucs != '\0'; ucs++)
    {
      *ucs = tolower(*ucs);
    }
  return s;
}

char *
_DEFUN (strupr, (s),
        char *s)
{
  unsigned char *ucs = (unsigned char *) s;
  for ( ; *ucs != '\0'; ucs++)
    {
      *ucs = toupper(*ucs);
    }
  return s;
}

---
Mike Burgess
Avanex Corporation
607-562-7169


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]