[libc][string] Add strcasecmp support
Add strcasecmp() for case insensitive string compares. There is no ISO standard function for this purpose but strcasecmp() is POSIX standard.
This commit is contained in:
committed by
Travis Geiselbrecht
parent
9ac5708eb5
commit
9ba1f165cd
@@ -21,6 +21,7 @@ void *memset (void *, int, size_t);
|
||||
char *strcat(char *, char const *);
|
||||
char *strchr(char const *, int) __PURE;
|
||||
int strcmp(char const *, char const *) __PURE;
|
||||
int strcasecmp(char const *, char const *) __PURE;
|
||||
char *strcpy(char *, char const *);
|
||||
char *strerror(int) __CONST;
|
||||
size_t strlen(char const *) __PURE;
|
||||
|
||||
@@ -8,6 +8,7 @@ C_STRING_OPS := \
|
||||
memcpy \
|
||||
memmove \
|
||||
memset \
|
||||
strcasecmp \
|
||||
strcat \
|
||||
strchr \
|
||||
strcmp \
|
||||
|
||||
28
lib/libc/string/strcasecmp.c
Normal file
28
lib/libc/string/strcasecmp.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||
** Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2008 Travis Geiselbrecht
|
||||
* Copyright 2022 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int strcasecmp(char const *cs, char const *ct) {
|
||||
signed char __res;
|
||||
|
||||
while (1) {
|
||||
if ((__res = tolower(*cs) - tolower(*ct)) != 0 || !*cs)
|
||||
break;
|
||||
cs++;
|
||||
ct++;
|
||||
}
|
||||
|
||||
return __res;
|
||||
}
|
||||
Reference in New Issue
Block a user