diff options
author | Andreas Kling <kling@serenityos.org> | 2022-11-18 09:52:22 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-11-19 11:11:13 +0100 |
commit | cc189ce0f367023af6d27b9b7ed7499318961eab (patch) | |
tree | 5374719a83206047de6bade0594b43c524acb0fb | |
parent | 7c4f5b58be6e8548a9940a6125ba09d1ee2907a0 (diff) | |
download | serenity-cc189ce0f367023af6d27b9b7ed7499318961eab.zip |
LibC: Make getpwent_r() behave more like glibc
Two things:
- We now fail with ENOENT when we reach the end of the database.
- Errors are returned directly instead of via errno.
-rw-r--r-- | Userland/Libraries/LibC/pwd.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/Userland/Libraries/LibC/pwd.cpp b/Userland/Libraries/LibC/pwd.cpp index 7fd6c85ba6..688d3f306c 100644 --- a/Userland/Libraries/LibC/pwd.cpp +++ b/Userland/Libraries/LibC/pwd.cpp @@ -134,35 +134,32 @@ int getpwent_r(struct passwd* passwd_buf, char* buffer, size_t buffer_size, stru while (true) { if (!s_stream || feof(s_stream)) { - errno = EIO; - return -1; + *passwd_entry_ptr = nullptr; + return ENOENT; } if (ferror(s_stream)) { - dbgln("getpwent(): Read error: {}", strerror(ferror(s_stream))); - errno = EIO; - return -1; + *passwd_entry_ptr = nullptr; + return ferror(s_stream); } ++s_line_number; char* s = fgets(buffer, buffer_size, s_stream); - // Silently tolerate an empty line at the end. if ((!s || !s[0]) && feof(s_stream)) { *passwd_entry_ptr = nullptr; - return 0; + return ENOENT; } if (strlen(s) == buffer_size - 1) { - errno = ERANGE; - return -1; + *passwd_entry_ptr = nullptr; + return ERANGE; } if (parse_pwddb_entry(buffer, *passwd_buf)) { *passwd_entry_ptr = passwd_buf; return 0; } - // Otherwise, proceed to the next line. } } |