[libc-commits] [libc] [libc] Add stub implementation for strptime. (PR #211088)
Alex Strelnikov via libc-commits
libc-commits at lists.llvm.org
Tue Jul 21 12:51:07 PDT 2026
https://github.com/strel-12 updated https://github.com/llvm/llvm-project/pull/211088
>From 165b76e85a9bc53094fa0604506d13d770bf1d26 Mon Sep 17 00:00:00 2001
From: Alex Strelnikov <strel at google.com>
Date: Tue, 21 Jul 2026 19:01:00 +0000
Subject: [PATCH 1/3] Add stub implementation for strptime.
---
libc/config/linux/aarch64/entrypoints.txt | 3 +++
libc/config/linux/x86_64/entrypoints.txt | 3 +++
libc/include/time.yaml | 8 ++++++++
libc/src/time/CMakeLists.txt | 11 +++++++++++
libc/src/time/strptime.cpp | 23 +++++++++++++++++++++++
libc/src/time/strptime.h | 22 ++++++++++++++++++++++
libc/test/src/time/CMakeLists.txt | 11 +++++++++++
libc/test/src/time/strptime_test.cpp | 19 +++++++++++++++++++
8 files changed, 100 insertions(+)
create mode 100644 libc/src/time/strptime.cpp
create mode 100644 libc/src/time/strptime.h
create mode 100644 libc/test/src/time/strptime_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 2e7b9276ab068..f8aa96e15077e 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1333,6 +1333,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 0a4fb747c2940..72fb8aa8a292c 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1570,6 +1570,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 76178542c6c9a..d4ccc0ce4b4f3 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -214,6 +214,17 @@ add_entrypoint_object(
libc.src.__support.macros.null_check
)
+add_entrypoint_object(
+ strptime
+ SRCS
+ strptime.cpp
+ HDRS
+ strptime.h
+ DEPENDS
+ libc.hdr.types.struct_tm
+ 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..e1d099034fc04
--- /dev/null
+++ b/libc/src/time/strptime.cpp
@@ -0,0 +1,23 @@
+//===-- Implementation of strptime function -------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#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 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..15107dcdd64b5
--- /dev/null
+++ b/libc/src/time/strptime.h
@@ -0,0 +1,22 @@
+//===-- Implementation header of strptime -----------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#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 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..f5b84ec5c8932
--- /dev/null
+++ b/libc/test/src/time/strptime_test.cpp
@@ -0,0 +1,19 @@
+//===-- Unittests for strptime --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#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);
+}
>From e5f424ea8b94648f8a5c02214b4f3705bd2bcc2c Mon Sep 17 00:00:00 2001
From: Alex Strelnikov <strel at google.com>
Date: Tue, 21 Jul 2026 19:11:50 +0000
Subject: [PATCH 2/3] Add missing CMakeLists dependency edit.
---
libc/src/time/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index d4ccc0ce4b4f3..3b8110ade345e 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -222,6 +222,7 @@ add_entrypoint_object(
strptime.h
DEPENDS
libc.hdr.types.struct_tm
+ libc.src.__support.common
libc.src.__support.macros.config
)
>From 7644c7b747bafb70f91f927a904409cb9007c871 Mon Sep 17 00:00:00 2001
From: Alex Strelnikov <strel at google.com>
Date: Tue, 21 Jul 2026 19:49:21 +0000
Subject: [PATCH 3/3] Fix file headers to use the current format.
---
libc/src/time/strptime.cpp | 7 ++++++-
libc/src/time/strptime.h | 7 ++++++-
libc/test/src/time/strptime_test.cpp | 7 ++++++-
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/libc/src/time/strptime.cpp b/libc/src/time/strptime.cpp
index e1d099034fc04..6e71ecde0e0ef 100644
--- a/libc/src/time/strptime.cpp
+++ b/libc/src/time/strptime.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of strptime function -------------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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"
diff --git a/libc/src/time/strptime.h b/libc/src/time/strptime.h
index 15107dcdd64b5..6678c42f0b304 100644
--- a/libc/src/time/strptime.h
+++ b/libc/src/time/strptime.h
@@ -1,10 +1,15 @@
-//===-- Implementation header of strptime -----------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
//
// 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
diff --git a/libc/test/src/time/strptime_test.cpp b/libc/test/src/time/strptime_test.cpp
index f5b84ec5c8932..8248e76589a8e 100644
--- a/libc/test/src/time/strptime_test.cpp
+++ b/libc/test/src/time/strptime_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for strptime --------------------------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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"
More information about the libc-commits
mailing list