diff options
author | Alex Brachet <abrachet@google.com> | 2023-01-11 05:38:33 +0000 |
---|---|---|
committer | Alex Brachet <abrachet@google.com> | 2023-01-11 05:38:33 +0000 |
commit | e9d571d3b6829f668e424d9dfce09f9ed7f297d9 (patch) | |
tree | 6c83db6dbdad46495432e6982adcc84d88367927 /libc/src/string/strncasecmp.cpp | |
parent | fae63a9a227aa341c4410dbd9e4650844a2c8961 (diff) | |
download | llvm-e9d571d3b6829f668e424d9dfce09f9ed7f297d9.tar.gz |
[libc] Implement str{,n}casecmp
Differential Revision: https://reviews.llvm.org/D141236
Diffstat (limited to 'libc/src/string/strncasecmp.cpp')
-rw-r--r-- | libc/src/string/strncasecmp.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libc/src/string/strncasecmp.cpp b/libc/src/string/strncasecmp.cpp new file mode 100644 index 000000000000..0fb2f81b17fe --- /dev/null +++ b/libc/src/string/strncasecmp.cpp @@ -0,0 +1,26 @@ +//===-- Implementation of strncasecmp -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/string/strncasecmp.h" + +#include "src/__support/common.h" +#include "src/__support/ctype_utils.h" +#include "src/string/memory_utils/strcmp_implementations.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(int, strncasecmp, + (const char *left, const char *right, size_t n)) { + auto case_cmp = [](char a, char b) { + return __llvm_libc::internal::tolower(a) - + __llvm_libc::internal::tolower(b); + }; + return strncmp_implementation(left, right, n, case_cmp); +} + +} // namespace __llvm_libc |