summaryrefslogtreecommitdiff
path: root/Userland/Utilities
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2023-05-03 18:45:18 -0400
committerAndreas Kling <kling@serenityos.org>2023-05-09 11:18:46 +0200
commit8c34959b53b2b72122fe6d2718d5dc060ff56875 (patch)
tree8e88ecd303fddce25ffc170d297bc76762f115da /Userland/Utilities
parent48b000a36cb22550e2c5314bc6c471812c963d0c (diff)
downloadserenity-8c34959b53b2b72122fe6d2718d5dc060ff56875.zip
AK: Add the `Input` word to input-only buffered streams
This concerns both `BufferedSeekable` and `BufferedFile`.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r--Userland/Utilities/cmp.cpp4
-rw-r--r--Userland/Utilities/comm.cpp6
-rw-r--r--Userland/Utilities/grep.cpp4
-rw-r--r--Userland/Utilities/lzcat.cpp2
-rw-r--r--Userland/Utilities/mount.cpp2
-rw-r--r--Userland/Utilities/sed.cpp11
-rw-r--r--Userland/Utilities/sort.cpp2
-rw-r--r--Userland/Utilities/sql.cpp4
-rw-r--r--Userland/Utilities/tar.cpp2
-rw-r--r--Userland/Utilities/uniq.cpp2
-rw-r--r--Userland/Utilities/xzcat.cpp2
11 files changed, 20 insertions, 21 deletions
diff --git a/Userland/Utilities/cmp.cpp b/Userland/Utilities/cmp.cpp
index c0b107d409..28de834dda 100644
--- a/Userland/Utilities/cmp.cpp
+++ b/Userland/Utilities/cmp.cpp
@@ -10,10 +10,10 @@
#include <LibCore/System.h>
#include <LibMain/Main.h>
-static ErrorOr<NonnullOwnPtr<Core::BufferedFile>> open_file_or_stdin(StringView filename)
+static ErrorOr<NonnullOwnPtr<Core::InputBufferedFile>> open_file_or_stdin(StringView filename)
{
auto file = TRY(Core::File::open_file_or_standard_stream(filename, Core::File::OpenMode::Read));
- return TRY(Core::BufferedFile::create(move(file)));
+ return TRY(Core::InputBufferedFile::create(move(file)));
}
ErrorOr<int> serenity_main(Main::Arguments arguments)
diff --git a/Userland/Utilities/comm.cpp b/Userland/Utilities/comm.cpp
index 31c23f23a8..8ca230a3a5 100644
--- a/Userland/Utilities/comm.cpp
+++ b/Userland/Utilities/comm.cpp
@@ -73,7 +73,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return false;
}
- auto buffered_file_or_error = Core::BufferedFile::create(file_or_error.release_value());
+ auto buffered_file_or_error = Core::InputBufferedFile::create(file_or_error.release_value());
if (buffered_file_or_error.is_error()) {
warnln("Failed to create buffer for file{} '{}': {}", file_number, path, buffered_file_or_error.error());
return false;
@@ -83,8 +83,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return true;
};
- OwnPtr<Core::BufferedFile> file1;
- OwnPtr<Core::BufferedFile> file2;
+ OwnPtr<Core::InputBufferedFile> file1;
+ OwnPtr<Core::InputBufferedFile> file2;
if (!(open_file(file1_path, file1, 1) && open_file(file2_path, file2, 2)))
return 1;
diff --git a/Userland/Utilities/grep.cpp b/Userland/Utilities/grep.cpp
index e819e23405..e73fddafc5 100644
--- a/Userland/Utilities/grep.cpp
+++ b/Userland/Utilities/grep.cpp
@@ -163,7 +163,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
if (!pattern_file.is_empty()) {
auto file = TRY(Core::File::open(pattern_file, Core::File::OpenMode::Read));
- auto buffered_file = TRY(Core::BufferedFile::create(move(file)));
+ auto buffered_file = TRY(Core::InputBufferedFile::create(move(file)));
Array<u8, PAGE_SIZE> buffer;
while (!buffered_file->is_eof()) {
auto next_pattern = TRY(buffered_file->read_line(buffer));
@@ -242,7 +242,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
auto handle_file = [&matches, binary_mode, count_lines, quiet_mode,
user_specified_multiple_files, &matched_line_count, &did_match_something](StringView filename, bool print_filename) -> ErrorOr<void> {
auto file = TRY(Core::File::open(filename, Core::File::OpenMode::Read));
- auto buffered_file = TRY(Core::BufferedFile::create(move(file)));
+ auto buffered_file = TRY(Core::InputBufferedFile::create(move(file)));
for (size_t line_number = 1; TRY(buffered_file->can_read_line()); ++line_number) {
Array<u8, PAGE_SIZE> buffer;
diff --git a/Userland/Utilities/lzcat.cpp b/Userland/Utilities/lzcat.cpp
index cc9d6ba936..320e814f9e 100644
--- a/Userland/Utilities/lzcat.cpp
+++ b/Userland/Utilities/lzcat.cpp
@@ -22,7 +22,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.parse(arguments);
auto file = TRY(Core::File::open_file_or_standard_stream(filename, Core::File::OpenMode::Read));
- auto buffered_file = TRY(Core::BufferedFile::create(move(file)));
+ auto buffered_file = TRY(Core::InputBufferedFile::create(move(file)));
auto stream = TRY(Compress::LzmaDecompressor::create_from_container(move(buffered_file)));
// Arbitrarily chosen buffer size.
diff --git a/Userland/Utilities/mount.cpp b/Userland/Utilities/mount.cpp
index e579a795a5..c5bc783531 100644
--- a/Userland/Utilities/mount.cpp
+++ b/Userland/Utilities/mount.cpp
@@ -113,7 +113,7 @@ static ErrorOr<void> mount_all()
bool all_ok = true;
auto process_fstab_entries = [&](StringView path) -> ErrorOr<void> {
auto file_unbuffered = TRY(Core::File::open(path, Core::File::OpenMode::Read));
- auto file = TRY(Core::BufferedFile::create(move(file_unbuffered)));
+ auto file = TRY(Core::InputBufferedFile::create(move(file_unbuffered)));
while (TRY(file->can_read_line())) {
auto line = TRY(file->read_line(buffer));
diff --git a/Userland/Utilities/sed.cpp b/Userland/Utilities/sed.cpp
index e6a4e72d01..9de2e59f62 100644
--- a/Userland/Utilities/sed.cpp
+++ b/Userland/Utilities/sed.cpp
@@ -613,7 +613,7 @@ enum class CycleDecision {
class File {
AK_MAKE_NONCOPYABLE(File);
- File(LexicalPath input_file_path, NonnullOwnPtr<Core::BufferedFile>&& file, OwnPtr<Core::File>&& output, OwnPtr<FileSystem::TempFile>&& temp_file)
+ File(LexicalPath input_file_path, NonnullOwnPtr<Core::InputBufferedFile>&& file, OwnPtr<Core::File>&& output, OwnPtr<FileSystem::TempFile>&& temp_file)
: m_input_file_path(move(input_file_path))
, m_file(move(file))
, m_output(move(output))
@@ -625,7 +625,7 @@ public:
// Used for -i mode.
static ErrorOr<File> create_with_output_file(LexicalPath input_path, NonnullOwnPtr<Core::File>&& file)
{
- auto buffered_file = TRY(Core::BufferedFile::create(move(file)));
+ auto buffered_file = TRY(Core::InputBufferedFile::create(move(file)));
auto temp_file = TRY(FileSystem::TempFile::create_temp_file());
// Open the file as read-write, since we need to later copy its contents to the original file.
auto output_file = TRY(Core::File::open(temp_file->path(), Core::File::OpenMode::ReadWrite | Core::File::OpenMode::Truncate));
@@ -635,7 +635,7 @@ public:
// Used for non -i mode.
static ErrorOr<File> create(LexicalPath input_path, NonnullOwnPtr<Core::File>&& file)
{
- auto buffered_file = TRY(Core::BufferedFile::create(move(file)));
+ auto buffered_file = TRY(Core::InputBufferedFile::create(move(file)));
return File { move(input_path), move(buffered_file), nullptr, nullptr };
}
@@ -650,7 +650,7 @@ public:
// We hack standard output into `File` to avoid having two versions of `write_pattern_space`.
return File {
LexicalPath { "/proc/self/fd/1" },
- TRY(Core::BufferedFile::create(TRY(Core::File::standard_input()))),
+ TRY(Core::InputBufferedFile::create(TRY(Core::File::standard_input()))),
TRY(Core::File::standard_output()),
nullptr,
};
@@ -697,12 +697,11 @@ public:
private:
LexicalPath m_input_file_path;
- NonnullOwnPtr<Core::BufferedFile> m_file;
+ NonnullOwnPtr<Core::InputBufferedFile> m_file;
// Only in use if we're editing in place.
OwnPtr<Core::File> m_output;
OwnPtr<FileSystem::TempFile> m_output_temp_file;
-
size_t m_line_number { 0 };
DeprecatedString m_current_line;
constexpr static size_t MAX_SUPPORTED_LINE_SIZE = 4096;
diff --git a/Userland/Utilities/sort.cpp b/Userland/Utilities/sort.cpp
index 6894ba3aae..25413ef699 100644
--- a/Userland/Utilities/sort.cpp
+++ b/Userland/Utilities/sort.cpp
@@ -62,7 +62,7 @@ struct Options {
static ErrorOr<void> load_file(Options options, StringView filename, Vector<Line>& lines, HashTable<Line>& seen)
{
- auto file = TRY(Core::BufferedFile::create(
+ auto file = TRY(Core::InputBufferedFile::create(
TRY(Core::File::open_file_or_standard_stream(filename, Core::File::OpenMode::Read))));
// FIXME: Unlimited line length
diff --git a/Userland/Utilities/sql.cpp b/Userland/Utilities/sql.cpp
index 64567268c4..514d21e522 100644
--- a/Userland/Utilities/sql.cpp
+++ b/Userland/Utilities/sql.cpp
@@ -151,7 +151,7 @@ private:
NonnullRefPtr<SQL::SQLClient> m_sql_client;
SQL::ConnectionID m_connection_id { 0 };
Core::EventLoop& m_loop;
- OwnPtr<Core::BufferedFile> m_input_file { nullptr };
+ OwnPtr<Core::InputBufferedFile> m_input_file { nullptr };
bool m_quit_when_files_read { false };
Vector<DeprecatedString> m_input_file_chain {};
Array<u8, 4096> m_buffer {};
@@ -166,7 +166,7 @@ private:
return {};
}
- auto buffered_file_or_error = Core::BufferedFile::create(file_or_error.release_value());
+ auto buffered_file_or_error = Core::InputBufferedFile::create(file_or_error.release_value());
if (buffered_file_or_error.is_error()) {
warnln("Input file {} could not be buffered: {}", file_name, buffered_file_or_error.error());
return {};
diff --git a/Userland/Utilities/tar.cpp b/Userland/Utilities/tar.cpp
index dcd3a4f4fc..9388578de5 100644
--- a/Userland/Utilities/tar.cpp
+++ b/Userland/Utilities/tar.cpp
@@ -74,7 +74,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!directory.is_empty())
TRY(Core::System::chdir(directory));
- NonnullOwnPtr<Stream> input_stream = TRY(Core::BufferedFile::create(TRY(Core::File::open_file_or_standard_stream(archive_file, Core::File::OpenMode::Read))));
+ NonnullOwnPtr<Stream> input_stream = TRY(Core::InputBufferedFile::create(TRY(Core::File::open_file_or_standard_stream(archive_file, Core::File::OpenMode::Read))));
if (gzip)
input_stream = make<Compress::GzipDecompressor>(move(input_stream));
diff --git a/Userland/Utilities/uniq.cpp b/Userland/Utilities/uniq.cpp
index f7609da2ca..e8f5abe82d 100644
--- a/Userland/Utilities/uniq.cpp
+++ b/Userland/Utilities/uniq.cpp
@@ -79,7 +79,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
- auto infile = TRY(Core::BufferedFile::create(TRY(Core::File::open_file_or_standard_stream(inpath, Core::File::OpenMode::Read))));
+ auto infile = TRY(Core::InputBufferedFile::create(TRY(Core::File::open_file_or_standard_stream(inpath, Core::File::OpenMode::Read))));
auto outfile = TRY(Core::File::open_file_or_standard_stream(outpath, Core::File::OpenMode::Write));
size_t count = 0;
diff --git a/Userland/Utilities/xzcat.cpp b/Userland/Utilities/xzcat.cpp
index 19837711e8..4d9cca37b4 100644
--- a/Userland/Utilities/xzcat.cpp
+++ b/Userland/Utilities/xzcat.cpp
@@ -22,7 +22,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.parse(arguments);
auto file = TRY(Core::File::open_file_or_standard_stream(filename, Core::File::OpenMode::Read));
- auto buffered_file = TRY(Core::BufferedFile::create(move(file)));
+ auto buffered_file = TRY(Core::InputBufferedFile::create(move(file)));
auto stream = TRY(Compress::XzDecompressor::create(move(buffered_file)));
// Arbitrarily chosen buffer size.