diff --git a/apps/base64.cpp b/apps/base64.cpp index 8bcf2db2..24cc32e4 100644 --- a/apps/base64.cpp +++ b/apps/base64.cpp @@ -18,16 +18,13 @@ Result luna_main(int argc, char** argv) auto file = TRY(os::File::open_input_file(path)); - auto output = os::File::standard_output(); - if (!decode) { auto data = TRY(file->read_all()); auto encoded = TRY(Base64::encode(data)); - output->write(encoded.view()); - output->write("\n"_sv); + os::println("%s", encoded.chars()); } else { @@ -35,7 +32,7 @@ Result luna_main(int argc, char** argv) auto decoded = TRY(Base64::decode(data.view(), allow_garbage)); - output->write(decoded); + os::File::standard_output()->write(decoded); } return 0; diff --git a/apps/date.cpp b/apps/date.cpp index 945203a8..17bde216 100644 --- a/apps/date.cpp +++ b/apps/date.cpp @@ -1,11 +1,11 @@ #include +#include #include -#include #include #include -int main(int argc, char** argv) +Result luna_main(int argc, char** argv) { StringView date; @@ -20,5 +20,7 @@ int main(int argc, char** argv) if (date.is_empty()) { now = time(NULL); } else { now = strtol(date.chars(), nullptr, 10); } - fputs(ctime(&now), stdout); + os::print("%s", ctime(&now)); + + return 0; } diff --git a/apps/ls.cpp b/apps/ls.cpp index 7955101f..3ea716d9 100644 --- a/apps/ls.cpp +++ b/apps/ls.cpp @@ -1,8 +1,6 @@ #include #include - -#include -#include +#include Result luna_main(int argc, char** argv) { @@ -27,14 +25,8 @@ Result luna_main(int argc, char** argv) auto files = TRY(dir->list(filter)); - int first_ent = 1; - for (const auto& file : files) - { - printf(first_ent ? "%s" : " %s", file.chars()); - first_ent = 0; - } - - putchar('\n'); + auto list = TRY(String::join(files, " "_sv)); + os::println("%s", list.chars()); return 0; } diff --git a/apps/sh.cpp b/apps/sh.cpp index 0d6bed61..f51a89fb 100644 --- a/apps/sh.cpp +++ b/apps/sh.cpp @@ -80,7 +80,7 @@ Result luna_main(int argc, char** argv) if (interactive) { 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()); diff --git a/libos/src/ArgumentParser.cpp b/libos/src/ArgumentParser.cpp index d13d05f6..d5e44281 100644 --- a/libos/src/ArgumentParser.cpp +++ b/libos/src/ArgumentParser.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -165,7 +166,7 @@ namespace os 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); } else if (looks_like_short_flag(arg)) @@ -213,7 +214,7 @@ namespace os 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); } @@ -235,8 +236,8 @@ namespace os { if (current_value_argument->required) { - fprintf(stderr, "%s: option '--%s' requires an argument\n", program_name.chars(), - current_value_argument->long_flag.chars()); + os::eprintln("%s: option '--%s' requires an argument", program_name.chars(), + current_value_argument->long_flag.chars()); short_usage(program_name); } else { *current_value_argument->out = current_value_argument->fallback; } @@ -247,7 +248,7 @@ namespace os { 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); } else { *arg.out = arg.fallback; } @@ -354,8 +355,8 @@ namespace os void ArgumentParser::short_usage(StringView program_name) { if (m_add_short_help_flag || m_add_long_help_flag) - fprintf(stderr, "Try running '%s %s' for more information.\n", program_name.chars(), - m_add_long_help_flag ? "--help" : "-h"); + os::eprintln("Try running '%s %s' for more information.", program_name.chars(), + m_add_long_help_flag ? "--help" : "-h"); exit(1); }