* Replaced our string compare functions (and memcmp()) with versions

that actually work correctly (and treat the data as unsigned 
  characters).
* This fixes bug #724.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24458 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-03-19 08:45:08 +00:00
parent b0543bd23b
commit c2383f9c82
4 changed files with 39 additions and 41 deletions

View File

@ -1,20 +1,23 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
/*
* Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT license.
*/
#include <sys/types.h>
#include <string.h>
int
memcmp(const void *cs, const void *ct, size_t count)
memcmp(const void *_a, const void *_b, size_t count)
{
const unsigned char *su1, *su2;
signed char res = 0;
const unsigned char *a = (const unsigned char *)_a;
const unsigned char *b = (const unsigned char *)_b;
for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0)
break;
return res;
while (count-- > 0) {
int cmp = *a++ - *b++;
if (cmp != 0)
return cmp;
}
return 0;
}

View File

@ -35,8 +35,6 @@
#include <string.h>
#include <ctype.h>
//typedef unsigned char u_char;
int
strcasecmp(const char *s1, const char *s2)
@ -44,9 +42,10 @@ strcasecmp(const char *s1, const char *s2)
const u_char *us1 = (const u_char *)s1;
const u_char *us2 = (const u_char *)s2;
while (tolower(*us1) == tolower(*us2++))
while (tolower(*us1) == tolower(*us2++)) {
if (*us1++ == '\0')
return 0;
}
return tolower(*us1) - tolower(*--us2);
}

View File

@ -1,21 +1,19 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
/*
* Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT license.
*/
#include <sys/types.h>
#include <stdbool.h>
#include <string.h>
int
strcmp(char const *cs, char const *ct)
strcmp(char const *a, char const *b)
{
signed char __res;
while (1) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
while (true) {
int cmp = (unsigned char)*a - (unsigned char)*b++;
if (cmp != 0 || *a++ == '\0')
return cmp;
}
return __res;
}

View File

@ -1,22 +1,20 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
/*
* Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT license.
*/
#include <sys/types.h>
#include <string.h>
int
strncmp(char const *cs, char const *ct, size_t count)
strncmp(char const *a, char const *b, size_t count)
{
signed char __res = 0;
while (count > 0) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
count--;
while (count-- > 0) {
int cmp = (unsigned char)*a - (unsigned char)*b++;
if (cmp != 0 || *a++ == '\0')
return cmp;
}
return __res;
return 0;
}