diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateEmojiData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateEmojiData.cpp index a8f356f686..83a30873c7 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateEmojiData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateEmojiData.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -45,7 +46,7 @@ static void set_image_path_for_emoji(StringView emoji_resource_path, Emoji& emoj } auto path = DeprecatedString::formatted("{}/{}.png", emoji_resource_path, builder.build()); - if (Core::Stream::File::exists(path)) + if (Core::File::exists(path)) emoji.image_path = move(path); } @@ -339,7 +340,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.parse(arguments); auto emoji_test_file = TRY(open_file(emoji_test_path, Core::Stream::OpenMode::Read)); - VERIFY(!emoji_resource_path.is_empty() && Core::Stream::File::exists(emoji_resource_path)); + VERIFY(!emoji_resource_path.is_empty() && Core::File::exists(emoji_resource_path)); EmojiData emoji_data {}; TRY(parse_emoji_test_data(*emoji_test_file, emoji_data)); diff --git a/Meta/Lagom/Tools/ConfigureComponents/main.cpp b/Meta/Lagom/Tools/ConfigureComponents/main.cpp index 4a15234c61..1bc0533ac7 100644 --- a/Meta/Lagom/Tools/ConfigureComponents/main.cpp +++ b/Meta/Lagom/Tools/ConfigureComponents/main.cpp @@ -234,7 +234,7 @@ int main() return 1; } - if (!Core::File::exists("components.ini")) { + if (!Core::File::exists("components.ini"sv)) { warnln("\e[31mError:\e[0m There is no 'components.ini' in the current working directory."); warnln(" It can be generated by running CMake with 'cmake ../.. -G Ninja'"); return 1; diff --git a/Tests/LibTLS/TestTLSHandshake.cpp b/Tests/LibTLS/TestTLSHandshake.cpp index b9675e6f9b..861efae70e 100644 --- a/Tests/LibTLS/TestTLSHandshake.cpp +++ b/Tests/LibTLS/TestTLSHandshake.cpp @@ -12,7 +12,7 @@ #include #include -static char const* ca_certs_file = "./ca_certs.ini"; +static StringView ca_certs_file = "./ca_certs.ini"sv; static int port = 443; constexpr auto DEFAULT_SERVER = "www.google.com"sv; diff --git a/Userland/Applications/Spreadsheet/main.cpp b/Userland/Applications/Spreadsheet/main.cpp index f575dada40..f95591f790 100644 --- a/Userland/Applications/Spreadsheet/main.cpp +++ b/Userland/Applications/Spreadsheet/main.cpp @@ -38,7 +38,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.parse(arguments); if (filename) { - if (!Core::File::exists(filename) || Core::File::is_directory(filename)) { + if (!Core::File::exists({ filename, strlen(filename) }) || Core::File::is_directory(filename)) { warnln("File does not exist or is a directory: {}", filename); return 1; } diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index 1af47ec5ee..0290d4205e 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -191,10 +192,9 @@ bool File::looks_like_shared_library(DeprecatedString const& filename) return filename.ends_with(".so"sv) || filename.contains(".so."sv); } -bool File::exists(DeprecatedString const& filename) +bool File::exists(StringView filename) { - struct stat st; - return stat(filename.characters(), &st) == 0; + return !Core::System::stat(filename).is_error(); } ErrorOr File::size(DeprecatedString const& filename) diff --git a/Userland/Libraries/LibCore/File.h b/Userland/Libraries/LibCore/File.h index 233e9c2364..6ac18fd95c 100644 --- a/Userland/Libraries/LibCore/File.h +++ b/Userland/Libraries/LibCore/File.h @@ -47,7 +47,7 @@ public: bool looks_like_shared_library() const; static bool looks_like_shared_library(DeprecatedString const& filename); - static bool exists(DeprecatedString const& filename); + static bool exists(StringView filename); static ErrorOr size(DeprecatedString const& filename); static DeprecatedString current_working_directory(); static DeprecatedString absolute_path(DeprecatedString const& path); diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index 3ff6ba837f..3f198cb760 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -165,11 +165,6 @@ ErrorOr> File::adopt_fd(int fd, OpenMode mode, ShouldCloseFi return file; } -bool File::exists(StringView filename) -{ - return !Core::System::stat(filename).is_error(); -} - ErrorOr> File::standard_input() { return File::adopt_fd(STDIN_FILENO, OpenMode::Read, ShouldCloseFileDescriptor::No); diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index f4048f386a..87e983c17d 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -220,7 +220,6 @@ class File final : public SeekableStream { public: static ErrorOr> open(StringView filename, OpenMode, mode_t = 0644); static ErrorOr> adopt_fd(int fd, OpenMode, ShouldCloseFileDescriptor = ShouldCloseFileDescriptor::Yes); - static bool exists(StringView filename); static ErrorOr> standard_input(); static ErrorOr> standard_output(); diff --git a/Userland/Services/WebContent/main.cpp b/Userland/Services/WebContent/main.cpp index 49311e52f6..b8687c844b 100644 --- a/Userland/Services/WebContent/main.cpp +++ b/Userland/Services/WebContent/main.cpp @@ -6,6 +6,7 @@ #include "ImageCodecPluginSerenity.h" #include +#include #include #include #include @@ -26,7 +27,7 @@ ErrorOr serenity_main(Main::Arguments) TRY(Core::System::pledge("stdio recvfd sendfd accept unix rpath")); // This must be first; we can't check if /tmp/webdriver exists once we've unveiled other paths. - if (Core::Stream::File::exists("/tmp/webdriver"sv)) + if (Core::File::exists("/tmp/webdriver"sv)) TRY(Core::System::unveil("/tmp/webdriver", "rw")); TRY(Core::System::unveil("/sys/kernel/processes", "r")); diff --git a/Userland/Utilities/touch.cpp b/Userland/Utilities/touch.cpp index 40ed302e44..3f4c654720 100644 --- a/Userland/Utilities/touch.cpp +++ b/Userland/Utilities/touch.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -239,7 +239,7 @@ ErrorOr serenity_main(Main::Arguments arguments) atime.tv_nsec = UTIME_OMIT; for (auto path : paths) { - if (Core::Stream::File::exists(path)) { + if (Core::File::exists(path)) { if (utimensat(AT_FDCWD, path.characters(), times, 0) == -1) err("failed to touch '{}': {}", path, strerror(errno)); } else if (!no_create_file) {