aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/string.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/string.c b/lib/string.c
index 78bd65c413..ecea755f40 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -206,16 +206,20 @@ size_t strlcat(char *dest, const char *src, size_t size)
* @cs: One string
* @ct: Another string
*/
-int strcmp(const char * cs,const char * ct)
+int strcmp(const char *cs, const char *ct)
{
- register signed char __res;
+ int ret;
while (1) {
- if ((__res = *cs - *ct++) != 0 || !*cs++)
+ unsigned char a = *cs++;
+ unsigned char b = *ct++;
+
+ ret = a - b;
+ if (ret || !b)
break;
}
- return __res;
+ return ret;
}
#endif
@@ -226,17 +230,20 @@ int strcmp(const char * cs,const char * ct)
* @ct: Another string
* @count: The maximum number of bytes to compare
*/
-int strncmp(const char * cs,const char * ct,size_t count)
+int strncmp(const char *cs, const char *ct, size_t count)
{
- register signed char __res = 0;
+ int ret = 0;
+
+ while (count--) {
+ unsigned char a = *cs++;
+ unsigned char b = *ct++;
- while (count) {
- if ((__res = *cs - *ct++) != 0 || !*cs++)
+ ret = a - b;
+ if (ret || !b)
break;
- count--;
}
- return __res;
+ return ret;
}
#endif