Serenity Operating System
1/*
2 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/Format.h>
8#include <AK/StringView.h>
9#include <AK/Vector.h>
10#include <LibMain/Main.h>
11#include <string.h>
12#include <time.h>
13
14namespace Main {
15
16static int s_return_code_for_errors = 1;
17
18int return_code_for_errors()
19{
20 return s_return_code_for_errors;
21}
22
23void set_return_code_for_errors(int code)
24{
25 s_return_code_for_errors = code;
26}
27
28}
29
30int main(int argc, char** argv)
31{
32 tzset();
33
34 Vector<StringView> arguments;
35 arguments.ensure_capacity(argc);
36 for (int i = 0; i < argc; ++i)
37 arguments.unchecked_append({ argv[i], strlen(argv[i]) });
38
39 auto result = serenity_main({
40 .argc = argc,
41 .argv = argv,
42 .strings = arguments.span(),
43 });
44 if (result.is_error()) {
45 auto error = result.release_error();
46 warnln("\033[31;1mRuntime error\033[0m: {}", error);
47#ifdef AK_OS_SERENITY
48 dbgln("\033[31;1mExiting with runtime error\033[0m: {}", error);
49#endif
50 return Main::return_code_for_errors();
51 }
52 return result.value();
53}