Skip to content

Commit ed5869d

Browse files
[libc] add wcslen
1 parent 58af7c8 commit ed5869d

File tree

7 files changed

+54
-0
lines changed

7 files changed

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

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

libc/hdrgen/yaml/wchar.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ functions:
2222
- type: const wchar_t *
2323
- type: wchar_t
2424
- type: size_t
25+
- name: wcslen
26+
standards:
27+
- stdc
28+
return_type: size_t
29+
arguments:
30+
- type: const wchar_t *

libc/src/wchar/wcslen.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation of wcslen ------------------------------------------===//
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/wcslen.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(size_t, wcslen, (const wchar_t *s)) {
16+
size_t length = 0;
17+
while (s[length++])
18+
;
19+
return length;
20+
}
21+
22+
} // namespace LIBC_NAMESPACE_DECL

libc/src/wchar/wcslen.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for wcslen ------------------------*- 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_WCSLEN_H
10+
#define LLVM_LIBC_SRC_WCHAR_WCSLEN_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+
size_t wcslen(const wchar_t *s);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_WCHAR_WCSLEN_H

0 commit comments

Comments
 (0)