mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
LibMain: Add the ability to configure the exit code on error
Some POSIX utilities are specified to return a specific value on error, which is not 1. `Main::set_return_code_for_errors()` lets you set it to that value.
This commit is contained in:
parent
60c228b914
commit
25c2a76d10
Notes:
sideshowbarker
2024-07-17 17:06:40 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/25c2a76d10 Pull-request: https://github.com/SerenityOS/serenity/pull/13137 Reviewed-by: https://github.com/bgianfo ✅
|
@ -11,6 +11,22 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
namespace Main {
|
||||||
|
|
||||||
|
static int s_return_code_for_errors = 1;
|
||||||
|
|
||||||
|
int return_code_for_errors()
|
||||||
|
{
|
||||||
|
return s_return_code_for_errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_return_code_for_errors(int code)
|
||||||
|
{
|
||||||
|
s_return_code_for_errors = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
tzset();
|
tzset();
|
||||||
|
@ -31,7 +47,7 @@ int main(int argc, char** argv)
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
dbgln("\033[31;1mExiting with runtime error\033[0m: {}", error);
|
dbgln("\033[31;1mExiting with runtime error\033[0m: {}", error);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return Main::return_code_for_errors();
|
||||||
}
|
}
|
||||||
return result.value();
|
return result.value();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ struct Arguments {
|
||||||
Span<StringView> strings;
|
Span<StringView> strings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int return_code_for_errors();
|
||||||
|
void set_return_code_for_errors(int);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments);
|
ErrorOr<int> serenity_main(Main::Arguments);
|
||||||
|
|
Loading…
Reference in a new issue