mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	LibCore: Rename Stream::read_all to read_until_eof
				
					
				
			This generally seems like a better name, especially if we somehow also need a better name for "read the entire buffer, but not the entire file" somewhere down the line.
This commit is contained in:
		
							parent
							
								
									5061a905ff
								
							
						
					
					
						commit
						ed4c2f2f8e
					
				
					 65 changed files with 88 additions and 88 deletions
				
			
		|  | @ -19,6 +19,6 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) | ||||||
| 
 | 
 | ||||||
|     auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream }; |     auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream }; | ||||||
| 
 | 
 | ||||||
|     (void)brotli_stream.read_all(); |     (void)brotli_stream.read_until_eof(); | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -826,7 +826,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open(arguments.strings[1], Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(arguments.strings[1], Core::Stream::OpenMode::Read)); | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     auto endpoints = parse(file_contents); |     auto endpoints = parse(file_contents); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -118,7 +118,7 @@ static ErrorOr<ApprovalDate> parse_approval_date(StringView const& str) | ||||||
| 
 | 
 | ||||||
| static ErrorOr<HashMap<DeprecatedString, PnpIdData>> parse_pnp_ids_database(Core::Stream::File& pnp_ids_file) | static ErrorOr<HashMap<DeprecatedString, PnpIdData>> parse_pnp_ids_database(Core::Stream::File& pnp_ids_file) | ||||||
| { | { | ||||||
|     auto pnp_ids_file_bytes = TRY(pnp_ids_file.read_all()); |     auto pnp_ids_file_bytes = TRY(pnp_ids_file.read_until_eof()); | ||||||
|     StringView pnp_ids_file_contents(pnp_ids_file_bytes); |     StringView pnp_ids_file_contents(pnp_ids_file_bytes); | ||||||
| 
 | 
 | ||||||
|     HashMap<DeprecatedString, PnpIdData> pnp_id_data; |     HashMap<DeprecatedString, PnpIdData> pnp_id_data; | ||||||
|  |  | ||||||
|  | @ -337,7 +337,7 @@ inline ErrorOr<NonnullOwnPtr<Core::Stream::BufferedFile>> open_file(StringView p | ||||||
| inline ErrorOr<JsonValue> read_json_file(StringView path) | inline ErrorOr<JsonValue> read_json_file(StringView path) | ||||||
| { | { | ||||||
|     auto file = TRY(open_file(path, Core::Stream::OpenMode::Read)); |     auto file = TRY(open_file(path, Core::Stream::OpenMode::Read)); | ||||||
|     auto buffer = TRY(file->read_all()); |     auto buffer = TRY(file->read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     return JsonValue::from_string(buffer); |     return JsonValue::from_string(buffer); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -157,7 +157,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|             return Error::from_string_view(s_error_string); |             return Error::from_string_view(s_error_string); | ||||||
|         } |         } | ||||||
|         auto file = file_or_error.release_value(); |         auto file = file_or_error.release_value(); | ||||||
|         auto string = MUST(file->read_all()); |         auto string = MUST(file->read_until_eof()); | ||||||
|         file_contents.append(DeprecatedString(ReadonlyBytes(string))); |         file_contents.append(DeprecatedString(ReadonlyBytes(string))); | ||||||
|     } |     } | ||||||
|     VERIFY(paths.size() == file_contents.size()); |     VERIFY(paths.size() == file_contents.size()); | ||||||
|  |  | ||||||
|  | @ -222,7 +222,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     args_parser.parse(arguments); |     args_parser.parse(arguments); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); | ||||||
|     auto content = TRY(file->read_all()); |     auto content = TRY(file->read_until_eof()); | ||||||
|     auto state_machine = parse_state_machine(content); |     auto state_machine = parse_state_machine(content); | ||||||
| 
 | 
 | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
|  |  | ||||||
|  | @ -19,13 +19,13 @@ static void run_test(StringView const file_name) | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|     auto cmp_file = MUST(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); |     auto cmp_file = MUST(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); | ||||||
|     auto cmp_data = MUST(cmp_file->read_all()); |     auto cmp_data = MUST(cmp_file->read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path); |     DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path); | ||||||
| 
 | 
 | ||||||
|     auto file = MUST(Core::Stream::File::open(path_compressed, Core::Stream::OpenMode::Read)); |     auto file = MUST(Core::Stream::File::open(path_compressed, Core::Stream::OpenMode::Read)); | ||||||
|     auto brotli_stream = Compress::BrotliDecompressionStream { *file }; |     auto brotli_stream = Compress::BrotliDecompressionStream { *file }; | ||||||
|     auto data = MUST(brotli_stream.read_all()); |     auto data = MUST(brotli_stream.read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     EXPECT_EQ(data, cmp_data); |     EXPECT_EQ(data, cmp_data); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -177,7 +177,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     DeprecatedString read_all() |     DeprecatedString read_all() | ||||||
|     { |     { | ||||||
|         auto all_output_or_error = m_input->read_all(); |         auto all_output_or_error = m_input->read_until_eof(); | ||||||
|         if (all_output_or_error.is_error()) { |         if (all_output_or_error.is_error()) { | ||||||
|             warnln("Got error: {} while reading runner output", all_output_or_error.error()); |             warnln("Got error: {} while reading runner output", all_output_or_error.error()); | ||||||
|             return ""sv; |             return ""sv; | ||||||
|  |  | ||||||
|  | @ -149,7 +149,7 @@ static Result<StringView, TestError> read_harness_file(StringView harness_file) | ||||||
|             }; |             }; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto contents_or_error = file_or_error.value()->read_all(); |         auto contents_or_error = file_or_error.value()->read_until_eof(); | ||||||
|         if (contents_or_error.is_error()) { |         if (contents_or_error.is_error()) { | ||||||
|             return TestError { |             return TestError { | ||||||
|                 NegativePhase::Harness, |                 NegativePhase::Harness, | ||||||
|  | @ -719,7 +719,7 @@ int main(int argc, char** argv) | ||||||
|         static size_t strict_length = use_strict.length(); |         static size_t strict_length = use_strict.length(); | ||||||
| 
 | 
 | ||||||
|         { |         { | ||||||
|             auto contents_or_error = file->read_all(); |             auto contents_or_error = file->read_until_eof(); | ||||||
|             if (contents_or_error.is_error()) { |             if (contents_or_error.is_error()) { | ||||||
|                 warnln("Could not read contents of file: {}", path); |                 warnln("Could not read contents of file: {}", path); | ||||||
|                 return exit_read_file_failure; |                 return exit_read_file_failure; | ||||||
|  |  | ||||||
|  | @ -113,7 +113,7 @@ private: | ||||||
|             return ""; |             return ""; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto file_contents_or_error = file_or_error.value()->read_all(); |         auto file_contents_or_error = file_or_error.value()->read_until_eof(); | ||||||
|         if (file_contents_or_error.is_error()) { |         if (file_contents_or_error.is_error()) { | ||||||
|             dbgln("Error: Could not read /sys/kernel/net/adapters: {}", file_contents_or_error.error()); |             dbgln("Error: Could not read /sys/kernel/net/adapters: {}", file_contents_or_error.error()); | ||||||
|             return ""; |             return ""; | ||||||
|  |  | ||||||
|  | @ -153,7 +153,7 @@ private: | ||||||
|             file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read)); |             file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read)); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto file_contents = TRY(file->read_all()); |         auto file_contents = TRY(file->read_until_eof()); | ||||||
|         return TRY(JsonValue::from_string(file_contents)); |         return TRY(JsonValue::from_string(file_contents)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -64,7 +64,7 @@ NetworkSettingsWidget::NetworkSettingsWidget() | ||||||
|     auto config_file = Core::ConfigFile::open_for_system("Network").release_value_but_fixme_should_propagate_errors(); |     auto config_file = Core::ConfigFile::open_for_system("Network").release_value_but_fixme_should_propagate_errors(); | ||||||
| 
 | 
 | ||||||
|     auto proc_net_adapters_file = Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read).release_value_but_fixme_should_propagate_errors(); |     auto proc_net_adapters_file = Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read).release_value_but_fixme_should_propagate_errors(); | ||||||
|     auto data = proc_net_adapters_file->read_all().release_value_but_fixme_should_propagate_errors(); |     auto data = proc_net_adapters_file->read_until_eof().release_value_but_fixme_should_propagate_errors(); | ||||||
|     JsonParser parser(data); |     JsonParser parser(data); | ||||||
|     JsonValue proc_net_adapters_json = parser.parse().release_value_but_fixme_should_propagate_errors(); |     JsonValue proc_net_adapters_json = parser.parse().release_value_but_fixme_should_propagate_errors(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -67,7 +67,7 @@ ErrorOr<NonnullOwnPtr<Presentation>> Presentation::load_from_file(StringView fil | ||||||
|     if (file_name.is_empty()) |     if (file_name.is_empty()) | ||||||
|         return ENOENT; |         return ENOENT; | ||||||
|     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(file_name, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(file_name, Core::Stream::OpenMode::Read)); | ||||||
|     auto contents = TRY(file->read_all()); |     auto contents = TRY(file->read_until_eof()); | ||||||
|     auto content_string = StringView { contents }; |     auto content_string = StringView { contents }; | ||||||
|     auto json = TRY(JsonValue::from_string(content_string)); |     auto json = TRY(JsonValue::from_string(content_string)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -113,7 +113,7 @@ Image::Image(NonnullRefPtr<ImageDecoderClient::Client> client, NonnullRefPtr<GUI | ||||||
| ErrorOr<void> Image::reload_image() | ErrorOr<void> Image::reload_image() | ||||||
| { | { | ||||||
|     auto file = TRY(Core::Stream::File::open(m_image_path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(m_image_path, Core::Stream::OpenMode::Read)); | ||||||
|     auto data = TRY(file->read_all()); |     auto data = TRY(file->read_until_eof()); | ||||||
|     auto maybe_decoded = m_client->decode_image(data); |     auto maybe_decoded = m_client->decode_image(data); | ||||||
|     if (!maybe_decoded.has_value() || maybe_decoded.value().frames.size() < 1) |     if (!maybe_decoded.has_value() || maybe_decoded.value().frames.size() < 1) | ||||||
|         return Error::from_string_view("Could not decode image"sv); |         return Error::from_string_view("Could not decode image"sv); | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ M3UParser::M3UParser() | ||||||
| NonnullOwnPtr<M3UParser> M3UParser::from_file(StringView path) | NonnullOwnPtr<M3UParser> M3UParser::from_file(StringView path) | ||||||
| { | { | ||||||
|     auto file_result = Core::Stream::File::open(path, Core::Stream::OpenMode::Read).release_value_but_fixme_should_propagate_errors(); |     auto file_result = Core::Stream::File::open(path, Core::Stream::OpenMode::Read).release_value_but_fixme_should_propagate_errors(); | ||||||
|     auto contents = file_result->read_all().release_value_but_fixme_should_propagate_errors(); |     auto contents = file_result->read_until_eof().release_value_but_fixme_should_propagate_errors(); | ||||||
|     auto use_utf8 = path.ends_with(".m3u8"sv, CaseSensitivity::CaseInsensitive); |     auto use_utf8 = path.ends_with(".m3u8"sv, CaseSensitivity::CaseInsensitive); | ||||||
|     return from_memory(DeprecatedString { contents, NoChomp }, use_utf8); |     return from_memory(DeprecatedString { contents, NoChomp }, use_utf8); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -86,7 +86,7 @@ static ErrorOr<void> fill_mounts(Vector<MountInfo>& output) | ||||||
|     // Output info about currently mounted filesystems.
 |     // Output info about currently mounted filesystems.
 | ||||||
|     auto file = TRY(Core::Stream::File::open("/sys/kernel/df"sv, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open("/sys/kernel/df"sv, Core::Stream::OpenMode::Read)); | ||||||
| 
 | 
 | ||||||
|     auto content = TRY(file->read_all()); |     auto content = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(content)); |     auto json = TRY(JsonValue::from_string(content)); | ||||||
| 
 | 
 | ||||||
|     TRY(json.as_array().try_for_each([&output](JsonValue const& value) -> ErrorOr<void> { |     TRY(json.as_array().try_for_each([&output](JsonValue const& value) -> ErrorOr<void> { | ||||||
|  |  | ||||||
|  | @ -411,7 +411,7 @@ Vector<GUI::ModelIndex> ProcessModel::matches(StringView searching, unsigned fla | ||||||
| static ErrorOr<DeprecatedString> try_read_command_line(pid_t pid) | static ErrorOr<DeprecatedString> try_read_command_line(pid_t pid) | ||||||
| { | { | ||||||
|     auto file = TRY(Core::Stream::File::open(DeprecatedString::formatted("/proc/{}/cmdline", pid), Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(DeprecatedString::formatted("/proc/{}/cmdline", pid), Core::Stream::OpenMode::Read)); | ||||||
|     auto data = TRY(file->read_all()); |     auto data = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(StringView { data.bytes() })); |     auto json = TRY(JsonValue::from_string(StringView { data.bytes() })); | ||||||
|     auto array = json.as_array().values(); |     auto array = json.as_array().values(); | ||||||
|     return DeprecatedString::join(" "sv, array); |     return DeprecatedString::join(" "sv, array); | ||||||
|  |  | ||||||
|  | @ -238,7 +238,7 @@ ErrorOr<NonnullOwnPtr<Profile>> Profile::load_from_perfcore_file(StringView path | ||||||
| { | { | ||||||
|     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); | ||||||
| 
 | 
 | ||||||
|     auto json = JsonValue::from_string(TRY(file->read_all())); |     auto json = JsonValue::from_string(TRY(file->read_until_eof())); | ||||||
|     if (json.is_error() || !json.value().is_object()) |     if (json.is_error() || !json.value().is_object()) | ||||||
|         return Error::from_string_literal("Invalid perfcore format (not a JSON object)"); |         return Error::from_string_literal("Invalid perfcore format (not a JSON object)"); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ void ScriptEditor::new_script_with_temp_name(DeprecatedString name) | ||||||
| ErrorOr<void> ScriptEditor::open_script_from_file(LexicalPath const& file_path) | ErrorOr<void> ScriptEditor::open_script_from_file(LexicalPath const& file_path) | ||||||
| { | { | ||||||
|     auto file = TRY(Core::Stream::File::open(file_path.string(), Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(file_path.string(), Core::Stream::OpenMode::Read)); | ||||||
|     auto buffer = TRY(file->read_all()); |     auto buffer = TRY(file->read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     set_text({ buffer.bytes() }); |     set_text({ buffer.bytes() }); | ||||||
|     m_path = file_path.string(); |     m_path = file_path.string(); | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(Core::Stream::S | ||||||
| 
 | 
 | ||||||
|     AllProcessesStatistics all_processes_statistics; |     AllProcessesStatistics all_processes_statistics; | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(proc_all_file.read_all()); |     auto file_contents = TRY(proc_all_file.read_until_eof()); | ||||||
|     auto json_obj = TRY(JsonValue::from_string(file_contents)).as_object(); |     auto json_obj = TRY(JsonValue::from_string(file_contents)).as_object(); | ||||||
|     json_obj.get("processes"sv).as_array().for_each([&](auto& value) { |     json_obj.get("processes"sv).as_array().for_each([&](auto& value) { | ||||||
|         const JsonObject& process_object = value.as_object(); |         const JsonObject& process_object = value.as_object(); | ||||||
|  |  | ||||||
|  | @ -47,12 +47,12 @@ bool Stream::read_or_error(Bytes buffer) | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<ByteBuffer> Stream::read_all(size_t block_size) | ErrorOr<ByteBuffer> Stream::read_until_eof(size_t block_size) | ||||||
| { | { | ||||||
|     return read_all_impl(block_size); |     return read_until_eof_impl(block_size); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<ByteBuffer> Stream::read_all_impl(size_t block_size, size_t expected_file_size) | ErrorOr<ByteBuffer> Stream::read_until_eof_impl(size_t block_size, size_t expected_file_size) | ||||||
| { | { | ||||||
|     ByteBuffer data; |     ByteBuffer data; | ||||||
|     data.ensure_capacity(expected_file_size); |     data.ensure_capacity(expected_file_size); | ||||||
|  | @ -243,12 +243,12 @@ ErrorOr<Bytes> File::read(Bytes buffer) | ||||||
|     return buffer.trim(nread); |     return buffer.trim(nread); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<ByteBuffer> File::read_all(size_t block_size) | ErrorOr<ByteBuffer> File::read_until_eof(size_t block_size) | ||||||
| { | { | ||||||
|     // Note: This is used as a heuristic, it's not valid for devices or virtual files.
 |     // Note: This is used as a heuristic, it's not valid for devices or virtual files.
 | ||||||
|     auto const potential_file_size = TRY(System::fstat(m_fd)).st_size; |     auto const potential_file_size = TRY(System::fstat(m_fd)).st_size; | ||||||
| 
 | 
 | ||||||
|     return read_all_impl(block_size, potential_file_size); |     return read_until_eof_impl(block_size, potential_file_size); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<size_t> File::write(ReadonlyBytes buffer) | ErrorOr<size_t> File::write(ReadonlyBytes buffer) | ||||||
|  |  | ||||||
|  | @ -39,7 +39,7 @@ public: | ||||||
|     /// Reads the stream until EOF, storing the contents into a ByteBuffer which
 |     /// Reads the stream until EOF, storing the contents into a ByteBuffer which
 | ||||||
|     /// is returned once EOF is encountered. The block size determines the size
 |     /// is returned once EOF is encountered. The block size determines the size
 | ||||||
|     /// of newly allocated chunks while reading.
 |     /// of newly allocated chunks while reading.
 | ||||||
|     virtual ErrorOr<ByteBuffer> read_all(size_t block_size = 4096); |     virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096); | ||||||
|     /// Discards the given number of bytes from the stream.
 |     /// Discards the given number of bytes from the stream.
 | ||||||
|     /// Unless specifically overwritten, this just uses read() to read into an
 |     /// Unless specifically overwritten, this just uses read() to read into an
 | ||||||
|     /// internal stack-based buffer.
 |     /// internal stack-based buffer.
 | ||||||
|  | @ -69,12 +69,12 @@ public: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
|     /// Provides a default implementation of read_all that works for streams
 |     /// Provides a default implementation of read_until_eof that works for streams
 | ||||||
|     /// that behave like POSIX file descriptors. expected_file_size can be
 |     /// that behave like POSIX file descriptors. expected_file_size can be
 | ||||||
|     /// passed as a heuristic for what the Stream subclass expects the file
 |     /// passed as a heuristic for what the Stream subclass expects the file
 | ||||||
|     /// content size to be in order to reduce allocations (does not affect
 |     /// content size to be in order to reduce allocations (does not affect
 | ||||||
|     /// actual reading).
 |     /// actual reading).
 | ||||||
|     ErrorOr<ByteBuffer> read_all_impl(size_t block_size, size_t expected_file_size = 0); |     ErrorOr<ByteBuffer> read_until_eof_impl(size_t block_size, size_t expected_file_size = 0); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| enum class SeekMode { | enum class SeekMode { | ||||||
|  | @ -238,7 +238,7 @@ public: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|     virtual ErrorOr<ByteBuffer> read_all(size_t block_size = 4096) override; |     virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096) override; | ||||||
|     virtual ErrorOr<size_t> write(ReadonlyBytes) override; |     virtual ErrorOr<size_t> write(ReadonlyBytes) override; | ||||||
|     virtual bool is_eof() const override; |     virtual bool is_eof() const override; | ||||||
|     virtual bool is_open() const override; |     virtual bool is_open() const override; | ||||||
|  |  | ||||||
|  | @ -86,7 +86,7 @@ static Optional<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Depre | ||||||
|         auto bufstream = bufstream_result.release_value(); |         auto bufstream = bufstream_result.release_value(); | ||||||
|         auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream }; |         auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream }; | ||||||
| 
 | 
 | ||||||
|         auto uncompressed = brotli_stream.read_all(); |         auto uncompressed = brotli_stream.read_until_eof(); | ||||||
|         if (uncompressed.is_error()) { |         if (uncompressed.is_error()) { | ||||||
|             dbgln("Job::handle_content_encoding: Brotli::decompress() failed: {}.", uncompressed.error()); |             dbgln("Job::handle_content_encoding: Brotli::decompress() failed: {}.", uncompressed.error()); | ||||||
|             return {}; |             return {}; | ||||||
|  |  | ||||||
|  | @ -104,7 +104,7 @@ static ErrorOr<bool> should_launch_server(DeprecatedString const& pid_path) | ||||||
|             return server_pid_file.release_error(); |             return server_pid_file.release_error(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto contents = server_pid_file.value()->read_all(); |         auto contents = server_pid_file.value()->read_until_eof(); | ||||||
|         if (contents.is_error()) { |         if (contents.is_error()) { | ||||||
|             warnln("Could not read SQLServer PID file '{}': {}", pid_path, contents.error()); |             warnln("Could not read SQLServer PID file '{}': {}", pid_path, contents.error()); | ||||||
|             return contents.release_error(); |             return contents.release_error(); | ||||||
|  |  | ||||||
|  | @ -243,7 +243,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             auto file = maybe_file.release_value(); |             auto file = maybe_file.release_value(); | ||||||
|             auto maybe_data = file->read_all(); |             auto maybe_data = file->read_until_eof(); | ||||||
|             if (maybe_data.is_error()) { |             if (maybe_data.is_error()) { | ||||||
|                 log_failure(request, maybe_data.error()); |                 log_failure(request, maybe_data.error()); | ||||||
|                 if (error_callback) |                 if (error_callback) | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ ErrorOr<int> serenity_main(Main::Arguments) | ||||||
|     auto config_file = TRY(Core::ConfigFile::open_for_system("Network")); |     auto config_file = TRY(Core::ConfigFile::open_for_system("Network")); | ||||||
| 
 | 
 | ||||||
|     auto proc_net_adapters_file = TRY(Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read)); |     auto proc_net_adapters_file = TRY(Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read)); | ||||||
|     auto data = TRY(proc_net_adapters_file->read_all()); |     auto data = TRY(proc_net_adapters_file->read_until_eof()); | ||||||
|     JsonParser parser(data); |     JsonParser parser(data); | ||||||
|     JsonValue proc_net_adapters_json = TRY(parser.parse()); |     JsonValue proc_net_adapters_json = TRY(parser.parse()); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -90,7 +90,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     if (!flag_set && !flag_delete) { |     if (!flag_set && !flag_delete) { | ||||||
|         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/arp"sv, Core::Stream::OpenMode::Read)); |         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/arp"sv, Core::Stream::OpenMode::Read)); | ||||||
|         auto file_contents = TRY(file->read_all()); |         auto file_contents = TRY(file->read_until_eof()); | ||||||
|         auto json = TRY(JsonValue::from_string(file_contents)); |         auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
| 
 | 
 | ||||||
|         Vector<JsonValue> sorted_regions = json.as_array().values(); |         Vector<JsonValue> sorted_regions = json.as_array().values(); | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     args_parser.parse(arguments); |     args_parser.parse(arguments); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(filepath, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(filepath, Core::Stream::OpenMode::Read)); | ||||||
|     ByteBuffer buffer = TRY(file->read_all()); |     ByteBuffer buffer = TRY(file->read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     TRY(Core::System::pledge("stdio")); |     TRY(Core::System::pledge("stdio")); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ static ErrorOr<Options> parse_options(Main::Arguments arguments) | ||||||
|     } else if (text.is_empty()) { |     } else if (text.is_empty()) { | ||||||
|         // Copy our stdin.
 |         // Copy our stdin.
 | ||||||
|         auto c_stdin = TRY(Core::Stream::File::standard_input()); |         auto c_stdin = TRY(Core::Stream::File::standard_input()); | ||||||
|         auto buffer = TRY(c_stdin->read_all()); |         auto buffer = TRY(c_stdin->read_until_eof()); | ||||||
|         dbgln("Read size {}", buffer.size()); |         dbgln("Read size {}", buffer.size()); | ||||||
|         dbgln("Read data: `{}`", StringView(buffer.bytes())); |         dbgln("Read data: `{}`", StringView(buffer.bytes())); | ||||||
|         options.data = buffer.bytes(); |         options.data = buffer.bytes(); | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     args_parser.parse(arguments); |     args_parser.parse(arguments); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); | ||||||
|     auto content = TRY(file->read_all()); |     auto content = TRY(file->read_until_eof()); | ||||||
|     StringView content_view(content); |     StringView content_view(content); | ||||||
| 
 | 
 | ||||||
|     Cpp::Lexer lexer(content); |     Cpp::Lexer lexer(content); | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     if (path.is_empty()) |     if (path.is_empty()) | ||||||
|         path = "Source/little/main.cpp"sv; |         path = "Source/little/main.cpp"sv; | ||||||
|     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); | ||||||
|     auto content = TRY(file->read_all()); |     auto content = TRY(file->read_until_eof()); | ||||||
|     StringView content_view(content); |     StringView content_view(content); | ||||||
| 
 | 
 | ||||||
|     ::Cpp::Preprocessor processor(path, content_view); |     ::Cpp::Preprocessor processor(path, content_view); | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     args_parser.parse(arguments); |     args_parser.parse(arguments); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); | ||||||
|     auto content = TRY(file->read_all()); |     auto content = TRY(file->read_until_eof()); | ||||||
|     DeprecatedString name = LexicalPath::basename(path); |     DeprecatedString name = LexicalPath::basename(path); | ||||||
|     Cpp::Preprocessor cpp(name, StringView { content }); |     Cpp::Preprocessor cpp(name, StringView { content }); | ||||||
|     auto tokens = cpp.process_and_lex(); |     auto tokens = cpp.process_and_lex(); | ||||||
|  |  | ||||||
|  | @ -40,7 +40,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|         outln("Filesystem    Blocks        Used    Available   Mount point"); |         outln("Filesystem    Blocks        Used    Available   Mount point"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
|     auto json_result = TRY(JsonValue::from_string(file_contents)); |     auto json_result = TRY(JsonValue::from_string(file_contents)); | ||||||
|     auto const& json = json_result.as_array(); |     auto const& json = json_result.as_array(); | ||||||
|     json.for_each([](auto& value) { |     json.for_each([](auto& value) { | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     bool color_output = TRY(Core::System::isatty(STDOUT_FILENO)); |     bool color_output = TRY(Core::System::isatty(STDOUT_FILENO)); | ||||||
| 
 | 
 | ||||||
|     auto hunks = Diff::from_text(TRY(file1->read_all()), TRY(file2->read_all())); |     auto hunks = Diff::from_text(TRY(file1->read_until_eof()), TRY(file2->read_until_eof())); | ||||||
|     for (auto const& hunk : hunks) { |     for (auto const& hunk : hunks) { | ||||||
|         auto original_start = hunk.original_start_line; |         auto original_start = hunk.original_start_line; | ||||||
|         auto target_start = hunk.target_start_line; |         auto target_start = hunk.target_start_line; | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ ErrorOr<int> serenity_main(Main::Arguments) | ||||||
|     TRY(Core::System::unveil(nullptr, nullptr)); |     TRY(Core::System::unveil(nullptr, nullptr)); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open("/sys/kernel/dmesg"sv, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open("/sys/kernel/dmesg"sv, Core::Stream::OpenMode::Read)); | ||||||
|     auto buffer = TRY(file->read_all()); |     auto buffer = TRY(file->read_until_eof()); | ||||||
|     out("{}", StringView { buffer }); |     out("{}", StringView { buffer }); | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -115,7 +115,7 @@ ErrorOr<void> parse_args(Main::Arguments arguments, Vector<DeprecatedString>& fi | ||||||
|         du_option.excluded_patterns.append(pattern); |         du_option.excluded_patterns.append(pattern); | ||||||
|     if (!exclude_from.is_empty()) { |     if (!exclude_from.is_empty()) { | ||||||
|         auto file = TRY(Core::Stream::File::open(exclude_from, Core::Stream::OpenMode::Read)); |         auto file = TRY(Core::Stream::File::open(exclude_from, Core::Stream::OpenMode::Read)); | ||||||
|         auto const buff = TRY(file->read_all()); |         auto const buff = TRY(file->read_until_eof()); | ||||||
|         if (!buff.is_empty()) { |         if (!buff.is_empty()) { | ||||||
|             DeprecatedString patterns = DeprecatedString::copy(buff, Chomp); |             DeprecatedString patterns = DeprecatedString::copy(buff, Chomp); | ||||||
|             du_option.excluded_patterns.extend(patterns.split('\n')); |             du_option.excluded_patterns.extend(patterns.split('\n')); | ||||||
|  |  | ||||||
|  | @ -87,7 +87,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     TRY(Core::System::unveil("/etc/timezone", "r")); |     TRY(Core::System::unveil("/etc/timezone", "r")); | ||||||
|     TRY(Core::System::unveil(nullptr, nullptr)); |     TRY(Core::System::unveil(nullptr, nullptr)); | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(file_contents)); |     auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
|     if (!json.is_array()) { |     if (!json.is_array()) { | ||||||
|         warnln("{} does not contain an array of quotes", path); |         warnln("{} does not contain an array of quotes", path); | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ static ErrorOr<bool> format_file(StringView path, bool inplace) | ||||||
|     auto open_mode = (inplace && !read_from_stdin) ? Core::Stream::OpenMode::ReadWrite : Core::Stream::OpenMode::Read; |     auto open_mode = (inplace && !read_from_stdin) ? Core::Stream::OpenMode::ReadWrite : Core::Stream::OpenMode::Read; | ||||||
|     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, open_mode)); |     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, open_mode)); | ||||||
| 
 | 
 | ||||||
|     auto contents = TRY(file->read_all()); |     auto contents = TRY(file->read_until_eof()); | ||||||
|     auto formatted_gml_or_error = GUI::GML::format_gml(contents); |     auto formatted_gml_or_error = GUI::GML::format_gml(contents); | ||||||
|     if (formatted_gml_or_error.is_error()) { |     if (formatted_gml_or_error.is_error()) { | ||||||
|         warnln("Failed to parse GML: {}", formatted_gml_or_error.error()); |         warnln("Failed to parse GML: {}", formatted_gml_or_error.error()); | ||||||
|  |  | ||||||
|  | @ -45,7 +45,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     TRY(Core::System::pledge("stdio")); |     TRY(Core::System::pledge("stdio")); | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(file_contents)); |     auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
| 
 | 
 | ||||||
|     if (use_color) { |     if (use_color) { | ||||||
|  |  | ||||||
|  | @ -32,7 +32,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     if (value_ipv4.is_empty() && value_adapter.is_empty() && value_mask.is_empty()) { |     if (value_ipv4.is_empty() && value_adapter.is_empty() && value_mask.is_empty()) { | ||||||
|         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read)); |         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read)); | ||||||
|         auto file_contents = TRY(file->read_all()); |         auto file_contents = TRY(file->read_until_eof()); | ||||||
|         auto json = TRY(JsonValue::from_string(file_contents)); |         auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
| 
 | 
 | ||||||
|         json.as_array().for_each([](auto& value) { |         json.as_array().for_each([](auto& value) { | ||||||
|  |  | ||||||
|  | @ -370,7 +370,7 @@ static JS::ThrowCompletionOr<JS::Value> load_json_impl(JS::VM& vm) | ||||||
|     if (file_or_error.is_error()) |     if (file_or_error.is_error()) | ||||||
|         return vm.throw_completion<JS::Error>(DeprecatedString::formatted("Failed to open '{}': {}", filename, file_or_error.error())); |         return vm.throw_completion<JS::Error>(DeprecatedString::formatted("Failed to open '{}': {}", filename, file_or_error.error())); | ||||||
| 
 | 
 | ||||||
|     auto file_contents_or_error = file_or_error.value()->read_all(); |     auto file_contents_or_error = file_or_error.value()->read_until_eof(); | ||||||
|     if (file_contents_or_error.is_error()) |     if (file_contents_or_error.is_error()) | ||||||
|         return vm.throw_completion<JS::Error>(DeprecatedString::formatted("Failed to read '{}': {}", filename, file_contents_or_error.error())); |         return vm.throw_completion<JS::Error>(DeprecatedString::formatted("Failed to read '{}': {}", filename, file_contents_or_error.error())); | ||||||
| 
 | 
 | ||||||
|  | @ -878,7 +878,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|             for (auto& path : script_paths) { |             for (auto& path : script_paths) { | ||||||
|                 auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); |                 auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); | ||||||
|                 auto file_contents = TRY(file->read_all()); |                 auto file_contents = TRY(file->read_until_eof()); | ||||||
|                 auto source = StringView { file_contents }; |                 auto source = StringView { file_contents }; | ||||||
| 
 | 
 | ||||||
|                 if (Utf8View { file_contents }.validate()) { |                 if (Utf8View { file_contents }.validate()) { | ||||||
|  |  | ||||||
|  | @ -47,7 +47,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     TRY(Core::System::pledge("stdio")); |     TRY(Core::System::pledge("stdio")); | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(file_contents)); |     auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
|     if (!dotted_key.is_empty()) { |     if (!dotted_key.is_empty()) { | ||||||
|         auto key_parts = dotted_key.split_view('.'); |         auto key_parts = dotted_key.split_view('.'); | ||||||
|  |  | ||||||
|  | @ -56,21 +56,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto maybe_command_set = command_set_file.value()->read_all(); |         auto maybe_command_set = command_set_file.value()->read_until_eof(); | ||||||
|         if (maybe_command_set.is_error()) { |         if (maybe_command_set.is_error()) { | ||||||
|             dbgln("Error: Could not read {}: {}", command_set_filename, maybe_command_set.error()); |             dbgln("Error: Could not read {}: {}", command_set_filename, maybe_command_set.error()); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         DeprecatedString command_set = StringView(maybe_command_set.value().bytes()); |         DeprecatedString command_set = StringView(maybe_command_set.value().bytes()); | ||||||
| 
 | 
 | ||||||
|         auto maybe_last_lba = last_lba_file.value()->read_all(); |         auto maybe_last_lba = last_lba_file.value()->read_until_eof(); | ||||||
|         if (maybe_last_lba.is_error()) { |         if (maybe_last_lba.is_error()) { | ||||||
|             dbgln("Error: Could not read {}: {}", last_lba_filename, maybe_last_lba.error()); |             dbgln("Error: Could not read {}: {}", last_lba_filename, maybe_last_lba.error()); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         DeprecatedString last_lba = StringView(maybe_last_lba.value().bytes()); |         DeprecatedString last_lba = StringView(maybe_last_lba.value().bytes()); | ||||||
| 
 | 
 | ||||||
|         auto maybe_sector_size = sector_size_file.value()->read_all(); |         auto maybe_sector_size = sector_size_file.value()->read_until_eof(); | ||||||
|         if (maybe_sector_size.is_error()) { |         if (maybe_sector_size.is_error()) { | ||||||
|             dbgln("Error: Could not read {}: {}", sector_size_filename, maybe_sector_size.error()); |             dbgln("Error: Could not read {}: {}", sector_size_filename, maybe_sector_size.error()); | ||||||
|             continue; |             continue; | ||||||
|  |  | ||||||
|  | @ -60,7 +60,7 @@ ErrorOr<int> serenity_main(Main::Arguments) | ||||||
|     TRY(Core::System::unveil(nullptr, nullptr)); |     TRY(Core::System::unveil(nullptr, nullptr)); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open("/sys/kernel/cpuinfo"sv, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open("/sys/kernel/cpuinfo"sv, Core::Stream::OpenMode::Read)); | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(file_contents)); |     auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
|     auto const& array = json.as_array(); |     auto const& array = json.as_array(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments) | ||||||
| 
 | 
 | ||||||
|     TRY(Core::System::pledge("stdio")); |     TRY(Core::System::pledge("stdio")); | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(proc_interrupts->read_all()); |     auto file_contents = TRY(proc_interrupts->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(file_contents)); |     auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
| 
 | 
 | ||||||
|     auto cpu_count = json.as_array().at(0).as_object().get("per_cpu_call_counts"sv).as_array().size(); |     auto cpu_count = json.as_array().at(0).as_object().get("per_cpu_call_counts"sv).as_array().size(); | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments) | ||||||
|     TRY(Core::System::pledge("stdio")); |     TRY(Core::System::pledge("stdio")); | ||||||
| 
 | 
 | ||||||
|     outln("Index    Name"); |     outln("Index    Name"); | ||||||
|     auto file_contents = TRY(jails_data->read_all()); |     auto file_contents = TRY(jails_data->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(file_contents)); |     auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
|     json.as_array().for_each([](auto& value) { |     json.as_array().for_each([](auto& value) { | ||||||
|         auto& jail = value.as_object(); |         auto& jail = value.as_object(); | ||||||
|  |  | ||||||
|  | @ -70,7 +70,7 @@ static Vector<OpenFile> get_open_files_by_pid(pid_t pid) | ||||||
|         outln("lsof: PID {}: {}", pid, file.error()); |         outln("lsof: PID {}: {}", pid, file.error()); | ||||||
|         return Vector<OpenFile>(); |         return Vector<OpenFile>(); | ||||||
|     } |     } | ||||||
|     auto data = file.value()->read_all(); |     auto data = file.value()->read_until_eof(); | ||||||
|     if (data.is_error()) { |     if (data.is_error()) { | ||||||
|         outln("lsof: PID {}: {}", pid, data.error()); |         outln("lsof: PID {}: {}", pid, data.error()); | ||||||
|         return {}; |         return {}; | ||||||
|  |  | ||||||
|  | @ -119,35 +119,35 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto vendor_id_contents = vendor_id_file.value()->read_all(); |         auto vendor_id_contents = vendor_id_file.value()->read_until_eof(); | ||||||
|         if (vendor_id_contents.is_error()) { |         if (vendor_id_contents.is_error()) { | ||||||
|             dbgln("Error: Could not read {}: {}", vendor_id_filename, vendor_id_contents.error()); |             dbgln("Error: Could not read {}: {}", vendor_id_filename, vendor_id_contents.error()); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         u32 vendor_id = read_hex_string_from_bytebuffer(vendor_id_contents.value()); |         u32 vendor_id = read_hex_string_from_bytebuffer(vendor_id_contents.value()); | ||||||
| 
 | 
 | ||||||
|         auto device_id_contents = device_id_file.value()->read_all(); |         auto device_id_contents = device_id_file.value()->read_until_eof(); | ||||||
|         if (device_id_contents.is_error()) { |         if (device_id_contents.is_error()) { | ||||||
|             dbgln("Error: Could not read {}: {}", device_id_filename, device_id_contents.error()); |             dbgln("Error: Could not read {}: {}", device_id_filename, device_id_contents.error()); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         u32 device_id = read_hex_string_from_bytebuffer(device_id_contents.value()); |         u32 device_id = read_hex_string_from_bytebuffer(device_id_contents.value()); | ||||||
| 
 | 
 | ||||||
|         auto revision_id_contents = revision_id_file.value()->read_all(); |         auto revision_id_contents = revision_id_file.value()->read_until_eof(); | ||||||
|         if (revision_id_contents.is_error()) { |         if (revision_id_contents.is_error()) { | ||||||
|             dbgln("Error: Could not read {}: {}", revision_id_filename, revision_id_contents.error()); |             dbgln("Error: Could not read {}: {}", revision_id_filename, revision_id_contents.error()); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         u32 revision_id = read_hex_string_from_bytebuffer(revision_id_contents.value()); |         u32 revision_id = read_hex_string_from_bytebuffer(revision_id_contents.value()); | ||||||
| 
 | 
 | ||||||
|         auto class_id_contents = class_id_file.value()->read_all(); |         auto class_id_contents = class_id_file.value()->read_until_eof(); | ||||||
|         if (class_id_contents.is_error()) { |         if (class_id_contents.is_error()) { | ||||||
|             dbgln("Error: Could not read {}: {}", class_id_filename, class_id_contents.error()); |             dbgln("Error: Could not read {}: {}", class_id_filename, class_id_contents.error()); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         u32 class_id = read_hex_string_from_bytebuffer(class_id_contents.value()); |         u32 class_id = read_hex_string_from_bytebuffer(class_id_contents.value()); | ||||||
| 
 | 
 | ||||||
|         auto subclass_id_contents = subclass_id_file.value()->read_all(); |         auto subclass_id_contents = subclass_id_file.value()->read_until_eof(); | ||||||
|         if (subclass_id_contents.is_error()) { |         if (subclass_id_contents.is_error()) { | ||||||
|             dbgln("Error: Could not read {}: {}", subclass_id_filename, subclass_id_contents.error()); |             dbgln("Error: Could not read {}: {}", subclass_id_filename, subclass_id_contents.error()); | ||||||
|             continue; |             continue; | ||||||
|  | @ -183,7 +183,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             auto bar_value_contents = bar_value_file.value()->read_all(); |             auto bar_value_contents = bar_value_file.value()->read_until_eof(); | ||||||
|             if (bar_value_contents.is_error()) { |             if (bar_value_contents.is_error()) { | ||||||
|                 dbgln("Error: Could not read {}: {}", bar_value_filename, bar_value_contents.error()); |                 dbgln("Error: Could not read {}: {}", bar_value_filename, bar_value_contents.error()); | ||||||
|                 continue; |                 continue; | ||||||
|  |  | ||||||
|  | @ -54,7 +54,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto contents = proc_usb_device.value()->read_all(); |         auto contents = proc_usb_device.value()->read_until_eof(); | ||||||
|         if (contents.is_error()) { |         if (contents.is_error()) { | ||||||
|             warnln("Failed to read {}: {}", full_path.string(), contents.error()); |             warnln("Failed to read {}: {}", full_path.string(), contents.error()); | ||||||
|             continue; |             continue; | ||||||
|  |  | ||||||
|  | @ -90,7 +90,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     TRY(Core::System::pledge("stdio proc")); |     TRY(Core::System::pledge("stdio proc")); | ||||||
| 
 | 
 | ||||||
|     dbgln("Loading man page from {}", TRY(page->path())); |     dbgln("Loading man page from {}", TRY(page->path())); | ||||||
|     auto buffer = TRY(file->read_all()); |     auto buffer = TRY(file->read_until_eof()); | ||||||
|     auto source = DeprecatedString::copy(buffer); |     auto source = DeprecatedString::copy(buffer); | ||||||
| 
 | 
 | ||||||
|     auto const title = TRY(String::from_utf8("SerenityOS manual"sv)); |     auto const title = TRY(String::from_utf8("SerenityOS manual"sv)); | ||||||
|  |  | ||||||
|  | @ -242,7 +242,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|         } |         } | ||||||
|         auto file = file_or_error.release_value(); |         auto file = file_or_error.release_value(); | ||||||
| 
 | 
 | ||||||
|         auto content_buffer_or_error = file->read_all(); |         auto content_buffer_or_error = file->read_until_eof(); | ||||||
|         if (content_buffer_or_error.is_error()) { |         if (content_buffer_or_error.is_error()) { | ||||||
|             warnln("Failed to read {}: {}", path, file_or_error.error()); |             warnln("Failed to read {}: {}", path, file_or_error.error()); | ||||||
|             // Since this should never happen anyway, fail early.
 |             // Since this should never happen anyway, fail early.
 | ||||||
|  |  | ||||||
|  | @ -45,7 +45,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     TRY(Core::System::pledge("stdio")); |     TRY(Core::System::pledge("stdio")); | ||||||
| 
 | 
 | ||||||
|     auto buffer = TRY(file->read_all()); |     auto buffer = TRY(file->read_until_eof()); | ||||||
|     dbgln("Read size {}", buffer.size()); |     dbgln("Read size {}", buffer.size()); | ||||||
| 
 | 
 | ||||||
|     auto input = DeprecatedString::copy(buffer); |     auto input = DeprecatedString::copy(buffer); | ||||||
|  |  | ||||||
|  | @ -150,7 +150,7 @@ static ErrorOr<void> print_mounts() | ||||||
|     // Output info about currently mounted filesystems.
 |     // Output info about currently mounted filesystems.
 | ||||||
|     auto df = TRY(Core::Stream::File::open("/sys/kernel/df"sv, Core::Stream::OpenMode::Read)); |     auto df = TRY(Core::Stream::File::open("/sys/kernel/df"sv, Core::Stream::OpenMode::Read)); | ||||||
| 
 | 
 | ||||||
|     auto content = TRY(df->read_all()); |     auto content = TRY(df->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(content)); |     auto json = TRY(JsonValue::from_string(content)); | ||||||
| 
 | 
 | ||||||
|     json.as_array().for_each([](auto& value) { |     json.as_array().for_each([](auto& value) { | ||||||
|  |  | ||||||
|  | @ -153,7 +153,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     if (!has_protocol_flag || flag_tcp) { |     if (!has_protocol_flag || flag_tcp) { | ||||||
|         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/tcp"sv, Core::Stream::OpenMode::Read)); |         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/tcp"sv, Core::Stream::OpenMode::Read)); | ||||||
|         auto file_contents = TRY(file->read_all()); |         auto file_contents = TRY(file->read_until_eof()); | ||||||
|         auto json_or_error = JsonValue::from_string(file_contents); |         auto json_or_error = JsonValue::from_string(file_contents); | ||||||
|         if (json_or_error.is_error()) { |         if (json_or_error.is_error()) { | ||||||
|             warnln("Error: {}", json_or_error.error()); |             warnln("Error: {}", json_or_error.error()); | ||||||
|  | @ -245,7 +245,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     if (!has_protocol_flag || flag_udp) { |     if (!has_protocol_flag || flag_udp) { | ||||||
|         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/udp"sv, Core::Stream::OpenMode::Read)); |         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/udp"sv, Core::Stream::OpenMode::Read)); | ||||||
|         auto file_contents = TRY(file->read_all()); |         auto file_contents = TRY(file->read_until_eof()); | ||||||
|         auto json = TRY(JsonValue::from_string(file_contents)); |         auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
| 
 | 
 | ||||||
|         Vector<JsonValue> sorted_regions = json.as_array().values(); |         Vector<JsonValue> sorted_regions = json.as_array().values(); | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ ErrorOr<int> serenity_main(Main::Arguments) | ||||||
|     if (file_or_error.is_error()) { |     if (file_or_error.is_error()) { | ||||||
|         outln("This account is currently not available."); |         outln("This account is currently not available."); | ||||||
|     } else { |     } else { | ||||||
|         auto message_from_file = TRY(file_or_error.value()->read_all()); |         auto message_from_file = TRY(file_or_error.value()->read_until_eof()); | ||||||
|         out("{}", StringView { message_from_file }); |         out("{}", StringView { message_from_file }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ ErrorOr<int> serenity_main(Main::Arguments) | ||||||
|     TRY(Core::System::pledge("stdio rpath")); |     TRY(Core::System::pledge("stdio rpath")); | ||||||
|     auto file = TRY(Core::Stream::File::open("/sys/kernel/cpuinfo"sv, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open("/sys/kernel/cpuinfo"sv, Core::Stream::OpenMode::Read)); | ||||||
| 
 | 
 | ||||||
|     auto buffer = TRY(file->read_all()); |     auto buffer = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(buffer)); |     auto json = TRY(JsonValue::from_string(buffer)); | ||||||
|     auto const& cpuinfo_array = json.as_array(); |     auto const& cpuinfo_array = json.as_array(); | ||||||
|     outln("{}", cpuinfo_array.size()); |     outln("{}", cpuinfo_array.size()); | ||||||
|  |  | ||||||
|  | @ -42,7 +42,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|         outln("Address{}           Size Access  Name", padding); |         outln("Address{}           Size Access  Name", padding); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(file_contents)); |     auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
| 
 | 
 | ||||||
|     Vector<JsonValue> sorted_regions = json.as_array().values(); |     Vector<JsonValue> sorted_regions = json.as_array().values(); | ||||||
|  |  | ||||||
|  | @ -90,7 +90,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     if (modify_action.is_empty()) { |     if (modify_action.is_empty()) { | ||||||
|         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/route"sv, Core::Stream::OpenMode::Read)); |         auto file = TRY(Core::Stream::File::open("/sys/kernel/net/route"sv, Core::Stream::OpenMode::Read)); | ||||||
|         auto file_contents = TRY(file->read_all()); |         auto file_contents = TRY(file->read_until_eof()); | ||||||
|         auto json = TRY(JsonValue::from_string(file_contents)); |         auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
| 
 | 
 | ||||||
|         outln("Kernel IP routing table"); |         outln("Kernel IP routing table"); | ||||||
|  |  | ||||||
|  | @ -30,7 +30,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     args_parser.parse(arguments); |     args_parser.parse(arguments); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, Core::Stream::OpenMode::Read)); | ||||||
|     ByteBuffer buffer = TRY(file->read_all()); |     ByteBuffer buffer = TRY(file->read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     u8 input_delimiter = is_zero_terminated ? '\0' : '\n'; |     u8 input_delimiter = is_zero_terminated ? '\0' : '\n'; | ||||||
|     Vector<Bytes> lines; |     Vector<Bytes> lines; | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ static DeprecatedString get_variable(StringView name) | ||||||
|         warnln("Failed to open {}: {}", path, file.error()); |         warnln("Failed to open {}: {}", path, file.error()); | ||||||
|         return {}; |         return {}; | ||||||
|     } |     } | ||||||
|     auto buffer = file.value()->read_all(); |     auto buffer = file.value()->read_until_eof(); | ||||||
|     if (buffer.is_error()) { |     if (buffer.is_error()) { | ||||||
|         warnln("Failed to read {}: {}", path, buffer.error()); |         warnln("Failed to read {}: {}", path, buffer.error()); | ||||||
|         return {}; |         return {}; | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ | ||||||
| static ErrorOr<void> tail_from_pos(Core::Stream::File& file, off_t startline) | static ErrorOr<void> tail_from_pos(Core::Stream::File& file, off_t startline) | ||||||
| { | { | ||||||
|     TRY(file.seek(startline + 1, Core::Stream::SeekMode::SetPosition)); |     TRY(file.seek(startline + 1, Core::Stream::SeekMode::SetPosition)); | ||||||
|     auto buffer = TRY(file.read_all()); |     auto buffer = TRY(file.read_until_eof()); | ||||||
|     out("{}", StringView { buffer }); |     out("{}", StringView { buffer }); | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
|  | @ -70,7 +70,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|         do { |         do { | ||||||
|             // FIXME: If f is the standard input, f->read_all() does not block
 |             // FIXME: If f is the standard input, f->read_all() does not block
 | ||||||
|             // anymore after sending EOF (^D), despite f->is_open() returning true.
 |             // anymore after sending EOF (^D), despite f->is_open() returning true.
 | ||||||
|             auto buffer = TRY(f->read_all(PAGE_SIZE)); |             auto buffer = TRY(f->read_until_eof(PAGE_SIZE)); | ||||||
|             auto line_count = StringView(buffer).count("\n"sv); |             auto line_count = StringView(buffer).count("\n"sv); | ||||||
|             auto bytes = buffer.bytes(); |             auto bytes = buffer.bytes(); | ||||||
|             size_t line_index = 0; |             size_t line_index = 0; | ||||||
|  | @ -108,7 +108,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|         auto watcher = TRY(Core::FileWatcher::create()); |         auto watcher = TRY(Core::FileWatcher::create()); | ||||||
|         watcher->on_change = [&](Core::FileWatcherEvent const& event) { |         watcher->on_change = [&](Core::FileWatcherEvent const& event) { | ||||||
|             if (event.type == Core::FileWatcherEvent::Type::ContentModified) { |             if (event.type == Core::FileWatcherEvent::Type::ContentModified) { | ||||||
|                 auto buffer_or_error = f->read_all(); |                 auto buffer_or_error = f->read_until_eof(); | ||||||
|                 if (buffer_or_error.is_error()) { |                 if (buffer_or_error.is_error()) { | ||||||
|                     auto error = buffer_or_error.error(); |                     auto error = buffer_or_error.error(); | ||||||
|                     warnln(error.string_literal()); |                     warnln(error.string_literal()); | ||||||
|  |  | ||||||
|  | @ -152,7 +152,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     auto fn = parse_target_name(type); |     auto fn = parse_target_name(type); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read)); | ||||||
|     auto input = TRY(file->read_all()); |     auto input = TRY(file->read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     return fn(input.data(), input.size()); |     return fn(input.data(), input.size()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -44,7 +44,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open("/var/run/utmp"sv, Core::Stream::OpenMode::ReadWrite)); |     auto file = TRY(Core::Stream::File::open("/var/run/utmp"sv, Core::Stream::OpenMode::ReadWrite)); | ||||||
| 
 | 
 | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
|     auto previous_json = TRY(JsonValue::from_string(file_contents)); |     auto previous_json = TRY(JsonValue::from_string(file_contents)); | ||||||
| 
 | 
 | ||||||
|     JsonObject json; |     JsonObject json; | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ ErrorOr<int> serenity_main(Main::Arguments) | ||||||
|     TRY(Core::System::unveil(nullptr, nullptr)); |     TRY(Core::System::unveil(nullptr, nullptr)); | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open("/var/run/utmp"sv, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open("/var/run/utmp"sv, Core::Stream::OpenMode::Read)); | ||||||
|     auto file_contents = TRY(file->read_all()); |     auto file_contents = TRY(file->read_until_eof()); | ||||||
|     auto json = TRY(JsonValue::from_string(file_contents)); |     auto json = TRY(JsonValue::from_string(file_contents)); | ||||||
|     if (!json.is_object()) { |     if (!json.is_object()) { | ||||||
|         warnln("Error: Could not parse /var/run/utmp"); |         warnln("Error: Could not parse /var/run/utmp"); | ||||||
|  |  | ||||||
|  | @ -372,7 +372,7 @@ static auto parse(StringView contents) | ||||||
|                     return Error::from_string_literal("NYI: Nonlocal entity"); |                     return Error::from_string_literal("NYI: Nonlocal entity"); | ||||||
| 
 | 
 | ||||||
|                 auto file = TRY(Core::Stream::File::open(url.path(), Core::Stream::OpenMode::Read)); |                 auto file = TRY(Core::Stream::File::open(url.path(), Core::Stream::OpenMode::Read)); | ||||||
|                 return DeprecatedString::copy(TRY(file->read_all())); |                 return DeprecatedString::copy(TRY(file->read_until_eof())); | ||||||
|             }, |             }, | ||||||
|         }, |         }, | ||||||
|     }; |     }; | ||||||
|  | @ -449,7 +449,7 @@ static void do_run_tests(XML::Document& document) | ||||||
| 
 | 
 | ||||||
|             warnln("Running test {}", url.path()); |             warnln("Running test {}", url.path()); | ||||||
| 
 | 
 | ||||||
|             auto contents = file_result.value()->read_all(); |             auto contents = file_result.value()->read_until_eof(); | ||||||
|             if (contents.is_error()) { |             if (contents.is_error()) { | ||||||
|                 warnln("Read error for {}: {}", url.path(), contents.error()); |                 warnln("Read error for {}: {}", url.path(), contents.error()); | ||||||
|                 s_test_results.set(url.path(), TestResult::RunnerFailed); |                 s_test_results.set(url.path(), TestResult::RunnerFailed); | ||||||
|  | @ -474,7 +474,7 @@ static void do_run_tests(XML::Document& document) | ||||||
|                     s_test_results.set(url.path(), TestResult::RunnerFailed); |                     s_test_results.set(url.path(), TestResult::RunnerFailed); | ||||||
|                     continue; |                     continue; | ||||||
|                 } |                 } | ||||||
|                 auto contents = file_result.value()->read_all(); |                 auto contents = file_result.value()->read_until_eof(); | ||||||
|                 if (contents.is_error()) { |                 if (contents.is_error()) { | ||||||
|                     warnln("Read error for {}: {}", out_path, contents.error()); |                     warnln("Read error for {}: {}", out_path, contents.error()); | ||||||
|                     s_test_results.set(url.path(), TestResult::RunnerFailed); |                     s_test_results.set(url.path(), TestResult::RunnerFailed); | ||||||
|  | @ -517,7 +517,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
|     s_path = Core::File::real_path_for(filename); |     s_path = Core::File::real_path_for(filename); | ||||||
|     auto file = TRY(Core::Stream::File::open(s_path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open(s_path, Core::Stream::OpenMode::Read)); | ||||||
|     auto contents = TRY(file->read_all()); |     auto contents = TRY(file->read_until_eof()); | ||||||
| 
 | 
 | ||||||
|     auto xml_parser = parse(contents); |     auto xml_parser = parse(contents); | ||||||
|     auto result = xml_parser.parse(); |     auto result = xml_parser.parse(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tim Schumacher
						Tim Schumacher