mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +00:00
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.
This commit is contained in:
parent
7c4f5b58be
commit
cc189ce0f3
1 changed files with 7 additions and 10 deletions
|
@ -134,35 +134,32 @@ int getpwent_r(struct passwd* passwd_buf, char* buffer, size_t buffer_size, stru
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!s_stream || feof(s_stream)) {
|
if (!s_stream || feof(s_stream)) {
|
||||||
errno = EIO;
|
*passwd_entry_ptr = nullptr;
|
||||||
return -1;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ferror(s_stream)) {
|
if (ferror(s_stream)) {
|
||||||
dbgln("getpwent(): Read error: {}", strerror(ferror(s_stream)));
|
*passwd_entry_ptr = nullptr;
|
||||||
errno = EIO;
|
return ferror(s_stream);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++s_line_number;
|
++s_line_number;
|
||||||
char* s = fgets(buffer, buffer_size, s_stream);
|
char* s = fgets(buffer, buffer_size, s_stream);
|
||||||
|
|
||||||
// Silently tolerate an empty line at the end.
|
|
||||||
if ((!s || !s[0]) && feof(s_stream)) {
|
if ((!s || !s[0]) && feof(s_stream)) {
|
||||||
*passwd_entry_ptr = nullptr;
|
*passwd_entry_ptr = nullptr;
|
||||||
return 0;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(s) == buffer_size - 1) {
|
if (strlen(s) == buffer_size - 1) {
|
||||||
errno = ERANGE;
|
*passwd_entry_ptr = nullptr;
|
||||||
return -1;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_pwddb_entry(buffer, *passwd_buf)) {
|
if (parse_pwddb_entry(buffer, *passwd_buf)) {
|
||||||
*passwd_entry_ptr = passwd_buf;
|
*passwd_entry_ptr = passwd_buf;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Otherwise, proceed to the next line.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue