Introduce common strcasecmp and strncasecmp implementations (#23840)
This commit is contained in:
16
lib/libc/musl/src/string/strcasecmp.c
vendored
16
lib/libc/musl/src/string/strcasecmp.c
vendored
@@ -1,16 +0,0 @@
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int strcasecmp(const char *_l, const char *_r)
|
||||
{
|
||||
const unsigned char *l=(void *)_l, *r=(void *)_r;
|
||||
for (; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++);
|
||||
return tolower(*l) - tolower(*r);
|
||||
}
|
||||
|
||||
int __strcasecmp_l(const char *l, const char *r, locale_t loc)
|
||||
{
|
||||
return strcasecmp(l, r);
|
||||
}
|
||||
|
||||
weak_alias(__strcasecmp_l, strcasecmp_l);
|
||||
17
lib/libc/musl/src/string/strncasecmp.c
vendored
17
lib/libc/musl/src/string/strncasecmp.c
vendored
@@ -1,17 +0,0 @@
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int strncasecmp(const char *_l, const char *_r, size_t n)
|
||||
{
|
||||
const unsigned char *l=(void *)_l, *r=(void *)_r;
|
||||
if (!n--) return 0;
|
||||
for (; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--);
|
||||
return tolower(*l) - tolower(*r);
|
||||
}
|
||||
|
||||
int __strncasecmp_l(const char *l, const char *r, size_t n, locale_t loc)
|
||||
{
|
||||
return strncasecmp(l, r, n);
|
||||
}
|
||||
|
||||
weak_alias(__strncasecmp_l, strncasecmp_l);
|
||||
Reference in New Issue
Block a user