[libc-commits] [libc] [libc] Add getpwnam_r and getpwuid_r entrypoints (PR #220833)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Thu Sep 3 08:49:35 PDT 2026
================
@@ -64,5 +77,40 @@ ErrorOr<struct passwd *> read_next() {
return &pwd_entry;
}
+ErrorOr<struct passwd *> find_by_name(cpp::string_view name, struct passwd *pwd,
+ cpp::span<char> buffer,
+ const char *path) {
+ if (!pwd)
+ return Error(EINVAL);
+ pwd::ScopedFlatFileDatabase<struct passwd> local_db(path ? path
+ : passwd_file_path);
+ auto matcher = [name](const struct passwd &entry) {
+ return cpp::string_view(entry.pw_name) == name;
+ };
+ auto res = local_db.lookup(matcher, pwd, buffer);
+ if (!res.has_value())
+ return Error(res.error());
+ if (!res.value())
+ return nullptr;
+ return pwd;
----------------
vonosmas wrote:
On success, we always return `pwd` (here and in similar function below), as `pwd` essentially acts as an output parameter. I wonder if we can have `find_by_name` and `find_by_uid` instead return ErrorOr<bool> find_by_name - and then we can just call `return local_db.lookup(matcher, pwd, buffer);` here, and call
```
auto res = passwd::find_by_name(name, pwd, cpp::span<char>(buffer, bufsize));
if (!res.has_value())
return res.error();
*result = res.value() ? pwd : nullptr;
return 0;
```
in entrypoints?
https://github.com/llvm/llvm-project/pull/220833
More information about the libc-commits
mailing list