mirror of
https://github.com/RGBCube/serenity
synced 2025-05-24 05:55:06 +00:00
file: Port to LibMain
This commit is contained in:
parent
27e63d40f1
commit
54f6829533
2 changed files with 10 additions and 14 deletions
|
@ -88,7 +88,7 @@ target_link_libraries(dmesg LibMain)
|
||||||
target_link_libraries(echo LibMain)
|
target_link_libraries(echo LibMain)
|
||||||
target_link_libraries(expr LibRegex)
|
target_link_libraries(expr LibRegex)
|
||||||
target_link_libraries(fdtdump LibDeviceTree LibMain)
|
target_link_libraries(fdtdump LibDeviceTree LibMain)
|
||||||
target_link_libraries(file LibGfx LibIPC LibCompress)
|
target_link_libraries(file LibGfx LibIPC LibCompress LibMain)
|
||||||
target_link_libraries(find LibMain)
|
target_link_libraries(find LibMain)
|
||||||
target_link_libraries(fortune LibMain)
|
target_link_libraries(fortune LibMain)
|
||||||
target_link_libraries(functrace LibDebug LibX86)
|
target_link_libraries(functrace LibDebug LibX86)
|
||||||
|
|
|
@ -10,9 +10,11 @@
|
||||||
#include <LibCore/FileStream.h>
|
#include <LibCore/FileStream.h>
|
||||||
#include <LibCore/MappedFile.h>
|
#include <LibCore/MappedFile.h>
|
||||||
#include <LibCore/MimeData.h>
|
#include <LibCore/MimeData.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
#include <LibELF/Validation.h>
|
#include <LibELF/Validation.h>
|
||||||
#include <LibGfx/ImageDecoder.h>
|
#include <LibGfx/ImageDecoder.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -132,12 +134,9 @@ static Optional<String> get_description_from_mime_type(const String& mime, const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector<const char*> paths;
|
Vector<const char*> paths;
|
||||||
bool flag_mime_only = false;
|
bool flag_mime_only = false;
|
||||||
|
@ -146,23 +145,20 @@ int main(int argc, char** argv)
|
||||||
args_parser.set_general_help("Determine type of files");
|
args_parser.set_general_help("Determine type of files");
|
||||||
args_parser.add_option(flag_mime_only, "Only print mime type", "mime-type", 'I');
|
args_parser.add_option(flag_mime_only, "Only print mime type", "mime-type", 'I');
|
||||||
args_parser.add_positional_argument(paths, "Files to identify", "files", Core::ArgsParser::Required::Yes);
|
args_parser.add_positional_argument(paths, "Files to identify", "files", Core::ArgsParser::Required::Yes);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
bool all_ok = true;
|
bool all_ok = true;
|
||||||
|
|
||||||
for (auto path : paths) {
|
for (auto path : paths) {
|
||||||
auto file = Core::File::construct(path);
|
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
if (file_or_error.is_error()) {
|
||||||
perror(path);
|
perror(path);
|
||||||
all_ok = false;
|
all_ok = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
auto file = file_or_error.release_value();
|
||||||
|
|
||||||
struct stat file_stat;
|
struct stat file_stat = TRY(Core::System::lstat(path));
|
||||||
if (lstat(path, &file_stat) < 0) {
|
|
||||||
perror("lstat");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto file_size_in_bytes = file_stat.st_size;
|
auto file_size_in_bytes = file_stat.st_size;
|
||||||
if (file->is_directory()) {
|
if (file->is_directory()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue