Skip to content

Commit 9dd063a

Browse files
[libc] add wcsrchr
1 parent 36ec861 commit 9dd063a

File tree

8 files changed

+69
-0
lines changed

8 files changed

+69
-0
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ set(TARGET_LIBC_ENTRYPOINTS
261261
libc.src.time.nanosleep
262262

263263
# wchar.h entrypoints
264+
libc.src.wchar.wcsrchr
264265
libc.src.wchar.wcschr
265266
libc.src.wchar.wcslen
266267
libc.src.wchar.wmemchr

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ set(TARGET_LIBC_ENTRYPOINTS
349349
libc.src.unistd.write
350350

351351
# wchar.h entrypoints
352+
libc.src.wchar.wcsrchr
352353
libc.src.wchar.wcschr
353354
libc.src.wchar.wcslen
354355
libc.src.wchar.wmemchr

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ set(TARGET_LIBC_ENTRYPOINTS
346346
libc.src.unistd.write
347347

348348
# wchar.h entrypoints
349+
libc.src.wchar.wcsrchr
349350
libc.src.wchar.wcschr
350351
libc.src.wchar.wcslen
351352
libc.src.wchar.wmemchr

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ set(TARGET_LIBC_ENTRYPOINTS
348348
libc.src.unistd.write
349349

350350
# wchar.h entrypoints
351+
libc.src.wchar.wcsrchr
351352
libc.src.wchar.wcschr
352353
libc.src.wchar.wcslen
353354
libc.src.wchar.wmemchr

libc/hdrgen/yaml/wchar.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ functions:
3535
arguments:
3636
- type: const wchar_t *
3737
- type: wchar_t
38+
- name: wcsrchr
39+
standards:
40+
- stdc
41+
return_type: const wchar_t *
42+
arguments:
43+
- type: const wchar_t *
44+
- type: wchar_t

libc/src/wchar/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,14 @@ add_entrypoint_object(
5858
.wmemchr
5959
libc.hdr.types.wchar_t
6060
)
61+
62+
add_entrypoint_object(
63+
wcsrchr
64+
SRCS
65+
wcsrchr.cpp
66+
HDRS
67+
wcsrchr.h
68+
DEPENDS
69+
.wcslen
70+
libc.hdr.types.wchar_t
71+
)

libc/src/wchar/wcsrchr.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Implementation of wcsrchr
2+
//------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "src/wchar/wcsrchr.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
#include "wcslen.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
LLVM_LIBC_FUNCTION(const wchar_t *, wcsrchr, (const wchar_t *s, wchar_t c)) {
18+
size_t length = wcslen(s);
19+
for (size_t i = 0; i < length; i++) {
20+
if (s[length - i] == c)
21+
return &s[length - i];
22+
}
23+
return nullptr;
24+
}
25+
26+
} // namespace LIBC_NAMESPACE_DECL

libc/src/wchar/wcsrchr.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for wcsrchr -----------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_WCHAR_WCSRCHR_H
10+
#define LLVM_LIBC_SRC_WCHAR_WCSRCHR_H
11+
12+
#include "hdr/types/wchar_t.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
const wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_WCHAR_WCSRCHR_H

0 commit comments

Comments
 (0)