Main.cpp 1.1 KB

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