X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/6c42153ad9362cc676ea66563bf400d7511b3b68..eed1bea439a5e3c62958fa1e524d527c4a2fb85d:/sbr/done.c diff --git a/sbr/done.c b/sbr/done.c index cf2e3080..5f2bc8db 100644 --- a/sbr/done.c +++ b/sbr/done.c @@ -1,8 +1,4 @@ - -/* - * done.c -- terminate the program - * - * $Id$ +/* done.c -- terminate the program * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -11,9 +7,26 @@ #include -int -done (int status) +static void (*altexit)(int) NORETURN = exit; + +/* set_done changes the path of done() from exit(3), or back to exit(3). + * Anything else will work, but a standard-error warning will report the + * old non-exit() value has been trampled. */ +void +set_done(void (*new)(int) NORETURN) +{ + generic_pointer gpo, gpn; + + if (altexit != exit && new != exit) { + gpo.f = (void (*)(void))altexit; + gpn.f = (void (*)(void))new; + inform("altexit trampled: %p %p", gpo.v, gpn.v); + } + altexit = new; +} + +void NORETURN +done(int status) { - exit (status); - return 1; /* dead code to satisfy the compiler */ + (*altexit)(status); }