LibC: Make sure that parse_pwddb_entry doesn't write to stderr

Library functions shouldn't write to stdout/stderr as that might not
be expected by the caller.
This commit is contained in:
Gunnar Beutner 2021-05-01 12:01:54 +02:00 committed by Andreas Kling
parent 302f9798ee
commit 17e5ba70b1
Notes: sideshowbarker 2024-07-18 18:49:50 +09:00

View file

@ -80,7 +80,7 @@ static bool parse_pwddb_entry(const String& line)
{
auto parts = line.split_view(':', true);
if (parts.size() != 7) {
fprintf(stderr, "getpwent(): Malformed entry on line %u\n", s_line_number);
dbgln("getpwent(): Malformed entry on line {}", s_line_number);
return false;
}
@ -94,12 +94,12 @@ static bool parse_pwddb_entry(const String& line)
auto uid = uid_string.to_uint();
if (!uid.has_value()) {
fprintf(stderr, "getpwent(): Malformed UID on line %u\n", s_line_number);
dbgln("getpwent(): Malformed UID on line {}", s_line_number);
return false;
}
auto gid = gid_string.to_uint();
if (!gid.has_value()) {
fprintf(stderr, "getpwent(): Malformed GID on line %u\n", s_line_number);
dbgln("getpwent(): Malformed GID on line {}", s_line_number);
return false;
}
@ -124,7 +124,7 @@ struct passwd* getpwent()
return nullptr;
if (ferror(s_stream)) {
fprintf(stderr, "getpwent(): Read error: %s\n", strerror(ferror(s_stream)));
dbgln("getpwent(): Read error: {}", strerror(ferror(s_stream)));
return nullptr;
}