Question

I was looking at the manual for longjmp and in the Errors part it says this:

ERRORS

If the contents of the env are corrupted, or correspond to an environment that has already returned, the longjmp() routine calls the routine longjmperror(3). If longjmperror() returns, the program is aborted (see abort(3)). The default version of longjmperror() prints the message ``longjmp botch'' to standard error and returns. User programs wishing to exit more gracefully should write their own versions of longjmperror().

How would i write my own version of longjmperror? From what i know in C you can't override functions and i really need the long jump to exit in a specific way when it doesn't find the point to jump to.

Was it helpful?

Solution

On Mac OS X (10.9.2, Mavericks) at any rate, the prototype for longjmperror() is:

void longjmperror(void);

You write a function with that signature. It must not return (or, rather, if it does, the program will be abort()ed). What you do in that function is your business, but bear in mind that things have gone moderately catastrophically wrong for the function to be called at all). It might log an error to your log file, or just write a more meaningful message before exiting (instead of aborting and perhaps core dumping).

You link the object file containing the function ahead of the system library. You are normally not expected to replace system functions, but this is one you are intended to override.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top