-/** @file \r
+/** @file\r
strncasecmp implementation\r
\r
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
* Copyright (c) 1987, 1993\r
- * The Regents of the University of California. All rights reserved.\r
+ * The Regents of the University of California. All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or without\r
* modification, are permitted provided that the following conditions\r
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
* SUCH DAMAGE.\r
\r
- $NetBSD: strncasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $\r
- strcasecmp.c 8.1 (Berkeley) 6/4/93\r
+ $NetBSD: strncasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $\r
+ strcasecmp.c 8.1 (Berkeley) 6/4/93\r
**/\r
#include <LibConfig.h>\r
#include <sys/cdefs.h>\r
#else\r
#include <lib/libkern/libkern.h>\r
#include <machine/limits.h>\r
-#endif \r
+#endif\r
\r
int\r
strncasecmp(const char *s1, const char *s2, size_t n)\r
{\r
+ int CompareVal;\r
\r
- _DIAGASSERT(s1 != NULL);\r
- _DIAGASSERT(s2 != NULL);\r
-\r
- if (n != 0) {\r
- const unsigned char *us1 = (const unsigned char *)s1,\r
- *us2 = (const unsigned char *)s2;\r
+ _DIAGASSERT(s1 != NULL);\r
+ _DIAGASSERT(s2 != NULL);\r
\r
- do {\r
- if (tolower(*us1) != tolower(*us2++))\r
- return (tolower(*us1) - tolower(*--us2));\r
- if (*us1++ == '\0')\r
- break;\r
- } while (--n != 0);\r
- }\r
- return (0);\r
+ if (n != 0) {\r
+ do {\r
+ CompareVal = tolower(*s1) - tolower(*s2);\r
+ if (CompareVal != 0) {\r
+ return (CompareVal);\r
+ }\r
+ ++s1;\r
+ ++s2;\r
+ if (*s1 == '\0') {\r
+ break;\r
+ }\r
+ } while (--n != 0);\r
+ }\r
+ return (0);\r
}\r