mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 11:24:58 +00:00

This creates an error that contains the name of the syscall that failed. This allows error handlers to print out the name of the call if they want to. :^)
36 lines
1,023 B
C++
36 lines
1,023 B
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Format.h>
|
|
#include <AK/StringView.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibMain/Main.h>
|
|
#include <string.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
Vector<StringView> arguments;
|
|
arguments.ensure_capacity(argc);
|
|
for (int i = 0; i < argc; ++i)
|
|
arguments.unchecked_append(argv[i]);
|
|
|
|
auto result = serenity_main({
|
|
.argc = argc,
|
|
.argv = argv,
|
|
.arguments = arguments.span(),
|
|
});
|
|
if (result.is_error()) {
|
|
auto error = result.release_error();
|
|
if (error.is_syscall())
|
|
warnln("Runtime error: {}: {} (errno={})", error.string_literal(), strerror(error.code()), error.code());
|
|
else if (error.is_errno())
|
|
warnln("Runtime error: {} (errno={})", strerror(error.code()), error.code());
|
|
else
|
|
warnln("Runtime error: {}", error.string_literal());
|
|
return 1;
|
|
}
|
|
return result.value();
|
|
}
|