Skip to content

Commit 58af7c8

Browse files
[libc] add wmemchr
1 parent 6e8a1a4 commit 58af7c8

File tree

8 files changed

+72
-0
lines changed

8 files changed

+72
-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.wmemchr
264265
libc.src.wchar.wctob
265266

266267
# locale.h entrypoints

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.wmemchr
352353
libc.src.wchar.wctob
353354
)
354355

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.wmemchr
349350
libc.src.wchar.wctob
350351
)
351352

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.wmemchr
351352
libc.src.wchar.wctob
352353
libc.src.wchar.btowc
353354
)

libc/hdrgen/yaml/wchar.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ functions:
1414
return_type: int
1515
arguments:
1616
- type: wint_t
17+
- name: wmemchr
18+
standards:
19+
- stdc
20+
return_type: const wchar_t *
21+
arguments:
22+
- type: const wchar_t *
23+
- type: wchar_t
24+
- type: size_t

libc/src/wchar/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@ add_entrypoint_object(
2222
libc.hdr.wchar_macros
2323
libc.src.__support.wctype_utils
2424
)
25+
26+
add_entrypoint_object(
27+
wmemchr
28+
SRCS
29+
wmemchr.cpp
30+
HDRS
31+
wmemchr.h
32+
DEPENDS
33+
libc.hdr.types.size_t
34+
libc.hdr.types.wchar_t
35+
libc.src.__support.wctype_utils
36+
)

libc/src/wchar/wmemchr.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Implementation of wmemchr -----------------------------------------===//
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/wmemchr.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/config.h"
12+
13+
namespace LIBC_NAMESPACE_DECL {
14+
15+
LLVM_LIBC_FUNCTION(const wchar_t *, wmemchr,
16+
(const wchar_t *s, wchar_t c, size_t n)) {
17+
for (size_t i = 0; i < n; i++) {
18+
if (s[i] == c) {
19+
return &s[i];
20+
}
21+
}
22+
23+
return nullptr;
24+
}
25+
26+
} // namespace LIBC_NAMESPACE_DECL

libc/src/wchar/wmemchr.h

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

0 commit comments

Comments
 (0)