1 | //===-- Implementation of wcsrchr -----------------------------------------===// |
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/wcsrchr.h" |
10 | |
11 | #include "hdr/types/wchar_t.h" |
12 | #include "src/__support/common.h" |
13 | #include "src/__support/macros/config.h" |
14 | #include "src/__support/macros/null_check.h" |
15 | |
16 | namespace LIBC_NAMESPACE_DECL { |
17 | |
18 | LLVM_LIBC_FUNCTION(const wchar_t *, wcsrchr, (const wchar_t *s, wchar_t c)) { |
19 | LIBC_CRASH_ON_NULLPTR(s); |
20 | |
21 | const wchar_t *last_occurrence = nullptr; |
22 | while (true) { |
23 | if (*s == c) |
24 | last_occurrence = s; |
25 | if (*s == L'\0') |
26 | return last_occurrence; |
27 | ++s; |
28 | } |
29 | } |
30 | |
31 | } // namespace LIBC_NAMESPACE_DECL |
32 | |