LibC: Replace fprintf(stderr) with warnln()

This commit is contained in:
Linus Groh 2021-05-31 14:39:36 +01:00
parent 028a337a6d
commit 1b81b63663
Notes: sideshowbarker 2024-07-18 17:07:04 +09:00
3 changed files with 11 additions and 16 deletions

View file

@ -77,7 +77,7 @@ static bool parse_grpdb_entry(const String& line)
{
auto parts = line.split_view(':', true);
if (parts.size() != 4) {
fprintf(stderr, "getgrent(): Malformed entry on line %u: '%s' has %zu parts\n", s_line_number, line.characters(), parts.size());
warnln("getgrent(): Malformed entry on line {}: '{}' has {} parts", s_line_number, line, parts.size());
return false;
}
@ -89,7 +89,7 @@ static bool parse_grpdb_entry(const String& line)
auto gid = gid_string.to_uint();
if (!gid.has_value()) {
fprintf(stderr, "getgrent(): Malformed GID on line %u\n", s_line_number);
warnln("getgrent(): Malformed GID on line {}", s_line_number);
return false;
}
@ -119,7 +119,7 @@ struct group* getgrent()
return nullptr;
if (ferror(s_stream)) {
fprintf(stderr, "getgrent(): Read error: %s\n", strerror(ferror(s_stream)));
warnln("getgrent(): Read error: {}", strerror(ferror(s_stream)));
return nullptr;
}

View file

@ -433,14 +433,14 @@ static bool fill_getserv_buffers(const char* line, ssize_t read)
// Services file entries should always at least contain
// name and port/protocol, separated by tabs.
if (split_line.size() < 2) {
fprintf(stderr, "getservent(): malformed services file\n");
warnln("getservent(): malformed services file");
return false;
}
__getserv_name_buffer = split_line[0];
auto port_protocol_split = String(split_line[1]).split('/');
if (port_protocol_split.size() < 2) {
fprintf(stderr, "getservent(): malformed services file\n");
warnln("getservent(): malformed services file");
return false;
}
auto number = port_protocol_split[0].to_int();
@ -615,7 +615,7 @@ static bool fill_getproto_buffers(const char* line, ssize_t read)
// This indicates an incorrect file format. Protocols file entries should
// always have at least a name and a protocol.
if (split_line.size() < 2) {
fprintf(stderr, "getprotoent(): malformed protocols file\n");
warnln("getprotoent(): malformed protocols file");
return false;
}
__getproto_name_buffer = split_line[0];

View file

@ -9,7 +9,6 @@
#include <AK/String.h>
#include <AK/Vector.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <termcap.h>
@ -21,8 +20,7 @@ char* BC;
int tgetent([[maybe_unused]] char* bp, [[maybe_unused]] const char* name)
{
if constexpr (TERMCAP_DEBUG)
fprintf(stderr, "tgetent: bp=%p, name='%s'\n", bp, name);
warnln_if(TERMCAP_DEBUG, "tgetent: bp={:p}, name='{}'", bp, name);
PC = '\0';
BC = const_cast<char*>("\033[D");
UP = const_cast<char*>("\033[A");
@ -80,8 +78,7 @@ static void ensure_caps()
char* tgetstr(const char* id, char** area)
{
ensure_caps();
if constexpr (TERMCAP_DEBUG)
fprintf(stderr, "tgetstr: id='%s'\n", id);
warnln_if(TERMCAP_DEBUG, "tgetstr: id='{}'", id);
auto it = caps->find(id);
if (it != caps->end()) {
char* ret = *area;
@ -90,7 +87,7 @@ char* tgetstr(const char* id, char** area)
*area += strlen(val) + 1;
return ret;
}
fprintf(stderr, "tgetstr: missing cap id='%s'\n", id);
warnln_if(TERMCAP_DEBUG, "tgetstr: missing cap id='{}'", id);
return nullptr;
}
@ -98,8 +95,7 @@ char* tgetstr(const char* id, char** area)
int tgetflag([[maybe_unused]] const char* id)
{
if constexpr (TERMCAP_DEBUG)
fprintf(stderr, "tgetflag: '%s'\n", id);
warnln_if(TERMCAP_DEBUG, "tgetflag: '{}'", id);
auto it = caps->find(id);
if (it != caps->end())
return 1;
@ -108,8 +104,7 @@ int tgetflag([[maybe_unused]] const char* id)
int tgetnum(const char* id)
{
if constexpr (TERMCAP_DEBUG)
fprintf(stderr, "tgetnum: '%s'\n", id);
warnln_if(TERMCAP_DEBUG, "tgetnum: '{}'", id);
auto it = caps->find(id);
if (it != caps->end())
return atoi((*it).value);