libos+apps: Use os::*print* instead of (f)printf
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-05-01 19:32:00 +02:00
parent a2303665fc
commit 48df90e636
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 19 additions and 27 deletions

View File

@ -18,16 +18,13 @@ Result<int> luna_main(int argc, char** argv)
auto file = TRY(os::File::open_input_file(path)); auto file = TRY(os::File::open_input_file(path));
auto output = os::File::standard_output();
if (!decode) if (!decode)
{ {
auto data = TRY(file->read_all()); auto data = TRY(file->read_all());
auto encoded = TRY(Base64::encode(data)); auto encoded = TRY(Base64::encode(data));
output->write(encoded.view()); os::println("%s", encoded.chars());
output->write("\n"_sv);
} }
else else
{ {
@ -35,7 +32,7 @@ Result<int> luna_main(int argc, char** argv)
auto decoded = TRY(Base64::decode(data.view(), allow_garbage)); auto decoded = TRY(Base64::decode(data.view(), allow_garbage));
output->write(decoded); os::File::standard_output()->write(decoded);
} }
return 0; return 0;

View File

@ -1,11 +1,11 @@
#include <os/ArgumentParser.h> #include <os/ArgumentParser.h>
#include <os/File.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
int main(int argc, char** argv) Result<int> luna_main(int argc, char** argv)
{ {
StringView date; StringView date;
@ -20,5 +20,7 @@ int main(int argc, char** argv)
if (date.is_empty()) { now = time(NULL); } if (date.is_empty()) { now = time(NULL); }
else { now = strtol(date.chars(), nullptr, 10); } else { now = strtol(date.chars(), nullptr, 10); }
fputs(ctime(&now), stdout); os::print("%s", ctime(&now));
return 0;
} }

View File

@ -1,8 +1,6 @@
#include <os/ArgumentParser.h> #include <os/ArgumentParser.h>
#include <os/Directory.h> #include <os/Directory.h>
#include <os/File.h>
#include <stdio.h>
#include <unistd.h>
Result<int> luna_main(int argc, char** argv) Result<int> luna_main(int argc, char** argv)
{ {
@ -27,14 +25,8 @@ Result<int> luna_main(int argc, char** argv)
auto files = TRY(dir->list(filter)); auto files = TRY(dir->list(filter));
int first_ent = 1; auto list = TRY(String::join(files, " "_sv));
for (const auto& file : files) os::println("%s", list.chars());
{
printf(first_ent ? "%s" : " %s", file.chars());
first_ent = 0;
}
putchar('\n');
return 0; return 0;
} }

View File

@ -80,7 +80,7 @@ Result<int> luna_main(int argc, char** argv)
if (interactive) if (interactive)
{ {
auto cwd = TRY(os::FileSystem::working_directory()); auto cwd = TRY(os::FileSystem::working_directory());
printf("%s@%s:%s%c ", username, hostname, cwd.chars(), prompt_end); os::print("%s@%s:%s%c ", username, hostname, cwd.chars(), prompt_end);
} }
auto cmd = TRY(input_file->read_line()); auto cmd = TRY(input_file->read_line());

View File

@ -1,5 +1,6 @@
#include <luna/StringBuilder.h> #include <luna/StringBuilder.h>
#include <os/ArgumentParser.h> #include <os/ArgumentParser.h>
#include <os/File.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/utsname.h> #include <sys/utsname.h>
@ -165,7 +166,7 @@ namespace os
if (found) continue; if (found) continue;
fprintf(stderr, "%s: unrecognized option '%s'\n", program_name.chars(), arg.chars()); os::eprintln("%s: unrecognized option '%s'", program_name.chars(), arg.chars());
short_usage(program_name); short_usage(program_name);
} }
else if (looks_like_short_flag(arg)) else if (looks_like_short_flag(arg))
@ -213,7 +214,7 @@ namespace os
if (found) continue; if (found) continue;
fprintf(stderr, "%s: invalid option -- '%c'\n", program_name.chars(), c); os::eprintln("%s: invalid option -- '%c'", program_name.chars(), c);
short_usage(program_name); short_usage(program_name);
} }
@ -235,8 +236,8 @@ namespace os
{ {
if (current_value_argument->required) if (current_value_argument->required)
{ {
fprintf(stderr, "%s: option '--%s' requires an argument\n", program_name.chars(), os::eprintln("%s: option '--%s' requires an argument", program_name.chars(),
current_value_argument->long_flag.chars()); current_value_argument->long_flag.chars());
short_usage(program_name); short_usage(program_name);
} }
else { *current_value_argument->out = current_value_argument->fallback; } else { *current_value_argument->out = current_value_argument->fallback; }
@ -247,7 +248,7 @@ namespace os
{ {
if (arg.required) if (arg.required)
{ {
fprintf(stderr, "%s: required argument '%s' not provided\n", program_name.chars(), arg.name.chars()); os::eprintln("%s: required argument '%s' not provided", program_name.chars(), arg.name.chars());
short_usage(program_name); short_usage(program_name);
} }
else { *arg.out = arg.fallback; } else { *arg.out = arg.fallback; }
@ -354,8 +355,8 @@ namespace os
void ArgumentParser::short_usage(StringView program_name) void ArgumentParser::short_usage(StringView program_name)
{ {
if (m_add_short_help_flag || m_add_long_help_flag) if (m_add_short_help_flag || m_add_long_help_flag)
fprintf(stderr, "Try running '%s %s' for more information.\n", program_name.chars(), os::eprintln("Try running '%s %s' for more information.", program_name.chars(),
m_add_long_help_flag ? "--help" : "-h"); m_add_long_help_flag ? "--help" : "-h");
exit(1); exit(1);
} }