* 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
+15 -12
View File
@@ -1,20 +1,23 @@
/* /*
** Copyright 2001, Travis Geiselbrecht. All rights reserved. * Copyright 2008, Axel Dörfler, [email protected].
** Distributed under the terms of the NewOS License. * Distributed under the terms of the MIT license.
*/ */
#include <sys/types.h>
#include <string.h> #include <string.h>
int 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; const unsigned char *a = (const unsigned char *)_a;
signed char res = 0; const unsigned char *b = (const unsigned char *)_b;
for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) while (count-- > 0) {
if ((res = *su1 - *su2) != 0) int cmp = *a++ - *b++;
break; if (cmp != 0)
return res; return cmp;
}
return 0;
} }
+2 -3
View File
@@ -35,8 +35,6 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
//typedef unsigned char u_char;
int int
strcasecmp(const char *s1, const char *s2) 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 *us1 = (const u_char *)s1;
const u_char *us2 = (const u_char *)s2; const u_char *us2 = (const u_char *)s2;
while (tolower(*us1) == tolower(*us2++)) while (tolower(*us1) == tolower(*us2++)) {
if (*us1++ == '\0') if (*us1++ == '\0')
return 0; return 0;
}
return tolower(*us1) - tolower(*--us2); return tolower(*us1) - tolower(*--us2);
} }
+11 -13
View File
@@ -1,21 +1,19 @@
/* /*
** Copyright 2001, Travis Geiselbrecht. All rights reserved. * Copyright 2008, Axel Dörfler, [email protected].
** Distributed under the terms of the NewOS License. * Distributed under the terms of the MIT license.
*/ */
#include <sys/types.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
int int
strcmp(char const *cs, char const *ct) strcmp(char const *a, char const *b)
{ {
signed char __res; while (true) {
int cmp = (unsigned char)*a - (unsigned char)*b++;
while (1) { if (cmp != 0 || *a++ == '\0')
if ((__res = *cs - *ct++) != 0 || !*cs++) return cmp;
break;
} }
return __res;
} }
+11 -13
View File
@@ -1,22 +1,20 @@
/* /*
** Copyright 2001, Travis Geiselbrecht. All rights reserved. * Copyright 2008, Axel Dörfler, [email protected].
** Distributed under the terms of the NewOS License. * Distributed under the terms of the MIT license.
*/ */
#include <sys/types.h>
#include <string.h> #include <string.h>
int 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) {
int cmp = (unsigned char)*a - (unsigned char)*b++;
while (count > 0) { if (cmp != 0 || *a++ == '\0')
if ((__res = *cs - *ct++) != 0 || !*cs++) return cmp;
break;
count--;
} }
return __res; return 0;
} }