[libc-commits] [libc] [libc] Add getpwnam and getpwuid entrypoints (PR #221169)
via libc-commits
libc-commits at lists.llvm.org
Fri Sep 4 01:46:54 PDT 2026
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 origin/main HEAD --extensions h,cpp -- libc/src/pwd/getpwnam.cpp libc/src/pwd/getpwnam.h libc/src/pwd/getpwuid.cpp libc/src/pwd/getpwuid.h libc/test/src/pwd/getpwnam_test.cpp libc/test/src/pwd/getpwuid_test.cpp libc/src/pwd/pwd_utils.cpp libc/src/pwd/pwd_utils.h --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/test/src/pwd/getpwnam_test.cpp b/libc/test/src/pwd/getpwnam_test.cpp
index 24b7ac18b..17b70b921 100644
--- a/libc/test/src/pwd/getpwnam_test.cpp
+++ b/libc/test/src/pwd/getpwnam_test.cpp
@@ -45,8 +45,8 @@ TEST_F(LlvmLibcGetpwnamTest, FirstAndLastEntries) {
const char *content = "first:x:100:100:first:/home/first:/bin/sh\n"
"middle:x:101:101:middle:/home/middle:/bin/sh\n"
"last:x:102:102:last:/home/last:/bin/sh\n";
- ScopedPasswdFile test_file(
- libc_make_test_file_path("getpwnam_boundary.test"), content);
+ ScopedPasswdFile test_file(libc_make_test_file_path("getpwnam_boundary.test"),
+ content);
struct passwd *pwd = LIBC_NAMESPACE::getpwnam("first");
ASSERT_NE(pwd, nullptr);
@@ -61,8 +61,8 @@ TEST_F(LlvmLibcGetpwnamTest, FirstAndLastEntries) {
TEST_F(LlvmLibcGetpwnamTest, NotFound) {
const char *content = "root:x:0:0:root:/root:/bin/bash\n";
- ScopedPasswdFile test_file(
- libc_make_test_file_path("getpwnam_notfound.test"), content);
+ ScopedPasswdFile test_file(libc_make_test_file_path("getpwnam_notfound.test"),
+ content);
// POSIX specifies that errno must not be changed when an entry is not found.
// Pre-set errno to confirm it remains untouched across the call.
@@ -101,16 +101,16 @@ TEST_F(LlvmLibcGetpwnamTest, FileOpenFailure) {
TEST_F(LlvmLibcGetpwnamTest, BufferTooSmall) {
// A line exceeding line_buffer (1024 bytes) triggers ERANGE.
char content[1100];
- LIBC_NAMESPACE::internal::strlcpy(content, "longuser:x:1000:1000:",
- sizeof(content));
+ LIBC_NAMESPACE::internal::strlcpy(content,
+ "longuser:x:1000:1000:", sizeof(content));
size_t cur = LIBC_NAMESPACE::internal::string_length(content);
for (; cur < 1050; ++cur)
content[cur] = 'a';
LIBC_NAMESPACE::internal::strlcpy(content + cur, ":/home/longuser:/bin/sh\n",
sizeof(content) - cur);
- ScopedPasswdFile test_file(
- libc_make_test_file_path("getpwnam_toosmall.test"), content);
+ ScopedPasswdFile test_file(libc_make_test_file_path("getpwnam_toosmall.test"),
+ content);
struct passwd *pwd = LIBC_NAMESPACE::getpwnam("longuser");
ASSERT_EQ(pwd, nullptr);
diff --git a/libc/test/src/pwd/getpwuid_test.cpp b/libc/test/src/pwd/getpwuid_test.cpp
index 64f9ad3dc..ac12e78a7 100644
--- a/libc/test/src/pwd/getpwuid_test.cpp
+++ b/libc/test/src/pwd/getpwuid_test.cpp
@@ -60,8 +60,8 @@ TEST_F(LlvmLibcGetpwuidTest, RootUidZero) {
TEST_F(LlvmLibcGetpwuidTest, NotFound) {
const char *content = "root:x:0:0:root:/root:/bin/bash\n";
- ScopedPasswdFile test_file(
- libc_make_test_file_path("getpwuid_notfound.test"), content);
+ ScopedPasswdFile test_file(libc_make_test_file_path("getpwuid_notfound.test"),
+ content);
// POSIX specifies that errno must not be changed when an entry is not found.
// Pre-set errno to confirm it remains untouched across the call.
@@ -100,16 +100,16 @@ TEST_F(LlvmLibcGetpwuidTest, FileOpenFailure) {
TEST_F(LlvmLibcGetpwuidTest, BufferTooSmall) {
// A line exceeding line_buffer (1024 bytes) triggers ERANGE.
char content[1100];
- LIBC_NAMESPACE::internal::strlcpy(content, "longuser:x:1000:1000:",
- sizeof(content));
+ LIBC_NAMESPACE::internal::strlcpy(content,
+ "longuser:x:1000:1000:", sizeof(content));
size_t cur = LIBC_NAMESPACE::internal::string_length(content);
for (; cur < 1050; ++cur)
content[cur] = 'a';
LIBC_NAMESPACE::internal::strlcpy(content + cur, ":/home/longuser:/bin/sh\n",
sizeof(content) - cur);
- ScopedPasswdFile test_file(
- libc_make_test_file_path("getpwuid_toosmall.test"), content);
+ ScopedPasswdFile test_file(libc_make_test_file_path("getpwuid_toosmall.test"),
+ content);
struct passwd *pwd = LIBC_NAMESPACE::getpwuid(1000);
ASSERT_EQ(pwd, nullptr);
``````````
</details>
https://github.com/llvm/llvm-project/pull/221169
More information about the libc-commits
mailing list