[libc-commits] [clang] [clang-tools-extra] [libc] [libc][c11] implement ctime (PR #107285)
via libc-commits
libc-commits at lists.llvm.org
Wed Sep 11 13:10:56 PDT 2024
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,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0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/107285 at github.com>
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 776495987272294de6aafbe73dab3e9ab445227a badde0df8c9202dfc9168a064db21567ef6557e4 --extensions h,cpp -- libc/src/time/ctime.cpp libc/src/time/ctime.h libc/src/time/ctime_r.cpp libc/src/time/ctime_r.h libc/test/src/time/ctime_r_test.cpp libc/test/src/time/ctime_test.cpp libc/src/time/time_utils.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/src/time/ctime.cpp b/libc/src/time/ctime.cpp
index 7fa2979ce1..80695895c3 100644
--- a/libc/src/time/ctime.cpp
+++ b/libc/src/time/ctime.cpp
@@ -20,7 +20,8 @@ LLVM_LIBC_FUNCTION(char *, ctime, (const time_t *t_ptr)) {
return nullptr;
}
static char buffer[TimeConstants::ASCTIME_BUFFER_SIZE];
- return time_utils::asctime(time_utils::localtime(t_ptr), buffer, TimeConstants::ASCTIME_MAX_BYTES);
+ return time_utils::asctime(time_utils::localtime(t_ptr), buffer,
+ TimeConstants::ASCTIME_MAX_BYTES);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/time/ctime_r.cpp b/libc/src/time/ctime_r.cpp
index 19b4ec9cfd..4d6bce780c 100644
--- a/libc/src/time/ctime_r.cpp
+++ b/libc/src/time/ctime_r.cpp
@@ -19,7 +19,8 @@ LLVM_LIBC_FUNCTION(char *, ctime_r, (const time_t *t_ptr, char *buffer)) {
if (*t_ptr > cpp::numeric_limits<int32_t>::max()) {
return nullptr;
}
- return time_utils::asctime(time_utils::localtime(t_ptr), buffer, TimeConstants::ASCTIME_MAX_BYTES);
+ return time_utils::asctime(time_utils::localtime(t_ptr), buffer,
+ TimeConstants::ASCTIME_MAX_BYTES);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/time/ctime_r_test.cpp b/libc/test/src/time/ctime_r_test.cpp
index 33feb838f1..26b41f98a8 100644
--- a/libc/test/src/time/ctime_r_test.cpp
+++ b/libc/test/src/time/ctime_r_test.cpp
@@ -45,13 +45,13 @@ TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) {
struct time_t t = 2147483647;
char *result;
// 2038-01-19 03:14:07. Test with a valid buffer size.
- char* result = LIBC_NAMESPACE::ctime_r(t, buffer);
+ char *result = LIBC_NAMESPACE::ctime_r(t, buffer);
ASSERT_STREQ("Tue Jan 19 03:14:07 2038\n", result);
}
TEST(LlvmLibcCtimeR, InvalidArgument) {
struct time_t t = 2147483648;
- char* result = call_ctime(&t);
+ char *result = call_ctime(&t);
ASSERT_ERRNO_EQ(EINVAL);
ASSERT_STREQ(nullptr, result);
}
diff --git a/libc/test/src/time/ctime_test.cpp b/libc/test/src/time/ctime_test.cpp
index 559e7f39f2..7e158f1df3 100644
--- a/libc/test/src/time/ctime_test.cpp
+++ b/libc/test/src/time/ctime_test.cpp
@@ -20,19 +20,19 @@ TEST(LlvmLibcCtime, Nullptr) {
TEST(LlvmLibcCtime, ValidUnixTimestamp0) {
struct time_t t = 0;
- char* result = LIBC_NAMESPACE::ctime(t);
+ char *result = LIBC_NAMESPACE::ctime(t);
ASSERT_STREQ("Thu Jan 1 00:00:00 1970\n", result);
}
TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) {
struct time_t t = 2147483647;
- char* result = LIBC_NAMESPACE::ctime(t);
+ char *result = LIBC_NAMESPACE::ctime(t);
ASSERT_STREQ("Tue Jan 19 03:14:07 2038\n", result);
}
TEST(LlvmLibcCtime, InvalidArgument) {
struct time_t t = 2147483648;
- char* result = LIBC_NAMESPACE::ctime(t);
+ char *result = LIBC_NAMESPACE::ctime(t);
ASSERT_ERRNO_EQ(EINVAL);
ASSERT_STREQ(nullptr, result);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/107285
More information about the libc-commits
mailing list