| 1 | //===-- Implementation of wmemcmp -----------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "src/wchar/wmemcmp.h" |
| 10 | |
| 11 | #include "hdr/types/size_t.h" |
| 12 | #include "hdr/types/wchar_t.h" |
| 13 | #include "src/__support/common.h" |
| 14 | #include "src/__support/macros/config.h" |
| 15 | #include "src/__support/macros/null_check.h" // LIBC_CRASH_ON_NULLPTR |
| 16 | |
| 17 | namespace LIBC_NAMESPACE_DECL { |
| 18 | |
| 19 | LLVM_LIBC_FUNCTION(int, wmemcmp, |
| 20 | (const wchar_t *s1, const wchar_t *s2, size_t n)) { |
| 21 | LIBC_CRASH_ON_NULLPTR(s1); |
| 22 | LIBC_CRASH_ON_NULLPTR(s2); |
| 23 | for (size_t i = 0; i < n; ++i) { |
| 24 | if (s1[i] != s2[i]) |
| 25 | return (int)(s1[i] - s2[i]); |
| 26 | } |
| 27 | // If it reaches the end, all n values must be the same. |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | } // namespace LIBC_NAMESPACE_DECL |
| 32 | |