aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 54110b16..38c87a41 100644
--- a/src/main.c
+++ b/src/main.c
@@ -56,17 +56,24 @@ int main(int argc, char *argv[]) {
char *name;
size_t len = strlen(BC_EXECPREFIX);
+ // Must set the locale properly in order to have the right error messages.
vm.locale = setlocale(LC_ALL, "");
+ // Set the start pledge().
bc_pledge(bc_pledge_start, NULL);
+ // Figure out the name of the calculator we are using. We can't use basename
+ // because it's not portable, but yes, this is stripping off the directory.
name = strrchr(argv[0], BC_FILE_SEP);
vm.name = (name == NULL) ? argv[0] : name + 1;
+ // If the name is longer than the length of the prefix, skip the prefix.
if (strlen(vm.name) > len) vm.name += len;
BC_SIG_LOCK;
+ // We *must* do this here. Otherwise, other code could not jump out all of
+ // the way.
bc_vec_init(&vm.jmp_bufs, sizeof(sigjmp_buf), BC_DTOR_NONE);
BC_SETJMP_LOCKED(exit);
@@ -76,6 +83,7 @@ int main(int argc, char *argv[]) {
#elif !BC_ENABLED
dc_main(argc, argv);
#else
+ // BC_IS_BC uses vm.name, which was set above. So we're good.
if (BC_IS_BC) bc_main(argc, argv);
else dc_main(argc, argv);
#endif
@@ -83,5 +91,6 @@ int main(int argc, char *argv[]) {
exit:
BC_SIG_MAYLOCK;
+ // Ensure we exit appropriately.
return bc_vm_atexit((int) vm.status);
}