[libc-commits] [libc] 39d3b93 - [libc] Add stub implementation for strptime. (#211088)
via libc-commits
libc-commits at lists.llvm.org
Mon Jul 27 08:19:26 PDT 2026
Author: Alex Strelnikov
Date: 2026-07-27T16:19:21+01:00
New Revision: 39d3b9344f4796e963d8d73bfd1e7cd3014d1fe6
URL: https://github.com/llvm/llvm-project/commit/39d3b9344f4796e963d8d73bfd1e7cd3014d1fe6
DIFF: https://github.com/llvm/llvm-project/commit/39d3b9344f4796e963d8d73bfd1e7cd3014d1fe6.diff
LOG: [libc] Add stub implementation for strptime. (#211088)
This PR adds a stub for `strptime` under
`LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS` for x86_64 and aarch64 as a
first step in implementing the function.
Added:
libc/src/time/strptime.cpp
libc/src/time/strptime.h
libc/test/src/time/strptime_test.cpp
Modified:
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/include/time.yaml
libc/src/time/CMakeLists.txt
libc/test/src/time/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 8eaa4871837bd..046fd301ea01b 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1335,6 +1335,9 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
# sys/ptrace.h entrypoints
libc.src.sys.ptrace.ptrace
+ # time.h entrypoints
+ libc.src.time.strptime
+
# wchar.h entrypoints
libc.src.wchar.swprintf
)
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index fb0886e2e650a..a86875fa4b9e8 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1572,6 +1572,9 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
# sys/ptrace.h entrypoints
libc.src.sys.ptrace.ptrace
+ # time.h entrypoints
+ libc.src.time.strptime
+
# wchar.h entrypoints
libc.src.wchar.swprintf
)
diff --git a/libc/include/time.yaml b/libc/include/time.yaml
index bd62379205d1e..2c18c5b8fc87f 100644
--- a/libc/include/time.yaml
+++ b/libc/include/time.yaml
@@ -132,6 +132,14 @@ functions:
- type: const char *__restrict
- type: const struct tm *__restrict
- type: locale_t
+ - name: strptime
+ standards:
+ - stdc
+ return_type: char *
+ arguments:
+ - type: const char *__restrict
+ - type: const char *__restrict
+ - type: struct tm *__restrict
- name: time
standards:
- stdc
diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index f6b1c370f6d84..b6e8a4ae84df8 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -214,6 +214,18 @@ add_entrypoint_object(
libc.src.__support.printf_core.writer
)
+add_entrypoint_object(
+ strptime
+ SRCS
+ strptime.cpp
+ HDRS
+ strptime.h
+ DEPENDS
+ libc.hdr.types.struct_tm
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
add_entrypoint_object(
time
SRCS
diff --git a/libc/src/time/strptime.cpp b/libc/src/time/strptime.cpp
new file mode 100644
index 0000000000000..0f844d1c9849f
--- /dev/null
+++ b/libc/src/time/strptime.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the definition of the strptime function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/time/strptime.h"
+#include "hdr/types/struct_tm.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(char *, strptime,
+ ([[maybe_unused]] const char *__restrict buf,
+ [[maybe_unused]] const char *__restrict format,
+ [[maybe_unused]] const struct tm *__restrict tm)) {
+ return nullptr;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/time/strptime.h b/libc/src/time/strptime.h
new file mode 100644
index 0000000000000..cb82aa060205c
--- /dev/null
+++ b/libc/src/time/strptime.h
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the declaration of the strptime function.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_TIME_STRPTIME_H
+#define LLVM_LIBC_SRC_TIME_STRPTIME_H
+
+#include "hdr/types/struct_tm.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+char *strptime(const char *__restrict buf, const char *__restrict format,
+ const struct tm *__restrict tm);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_TIME_STRPTIME_H
diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index eb633a814333e..ad5017369b0a7 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -226,6 +226,17 @@ add_libc_test(
libc.src.time.strftime
)
+add_libc_test(
+ strptime_test
+ SUITE
+ libc_time_unittests
+ SRCS
+ strptime_test.cpp
+ DEPENDS
+ libc.hdr.types.struct_tm
+ libc.src.time.strptime
+)
+
add_libc_unittest(
time_test
SUITE
diff --git a/libc/test/src/time/strptime_test.cpp b/libc/test/src/time/strptime_test.cpp
new file mode 100644
index 0000000000000..8248e76589a8e
--- /dev/null
+++ b/libc/test/src/time/strptime_test.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains unit tests for strptime.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/types/struct_tm.h"
+#include "src/time/strptime.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcStrptimeTest, StubReturnsNull) {
+ struct tm time;
+ char *result;
+
+ result = LIBC_NAMESPACE::strptime("13:23:45", "%T", &time);
+ EXPECT_EQ(result, nullptr);
+}
More information about the libc-commits
mailing list