HANDLECOND(3)
π
HANDLECOND(3) β like, the handlecond() page from SchilyΒ΄s LIBRARY FUNCTIONS β¨
okay bestie, sit down, grab a strawberry π β we're learning how to set up a condition handler, and honestly? it's giving stack frame main character energy.
β¨ NAME β¨
handlecond() β sets a function to handle a condition π
π¦ SYNOPSIS π¦
#include <schily/sigblk.h>
void
handlecond(signame, sp, func, arg1)
char *signame;
SIGBLK *sp;
int (*func)();
long arg1;
void
starthandlecond(sigfirst)
SIGBLK *sigfirst;
void
unhandlecond(sigfirst)
SIGBLK *sigfirst;
πΈ DESCRIPTION πΈ
So handlecond() sets up a handler for a condition. Important: the user must explicitly allocate the condition block and pass it in β nobody's doing that for you, bestie π
.
handlecond() establishes function func as the condition handler for the condition signame. And arg1? That gets passed to func at the time of condition signalling. Also, the signame "any_other" catches all conditions β like the ultimate catch-all, no cap π
The specified function gets called with the actual condition being signalled, with arguments from the latest handlecond() call for that function in the given frame and from the call to raisecond(). For instance:
int func (signame, arg1, arg2)
char *signame; /* the actual condition being
/* signalled */
int arg1; /* arg1 comes from the handle
/* call that set up the handler */
int arg2; /* arg2 comes from the raise call */
If the function returns TRUE (non-zero), it's assumed the condition has been successfully handled β slay π. Otherwise, the condition is signalled farther down the stack. literally just cascading down, iykyk.
starthandlecond() sets an initial marker to the current stack frame. It needs to be called before handlecond() may be used, and the argument needs to be a variable local to the current function.
unhandlecond() needs to be called before a function may call return or fall out of the function body. The argument needs to be the same as used for the starthandlecond() function. same one, bestie, don't get cute with it π
π RETURNS π
none β that's it, that's the whole section, we love a low-effort king π
π NOTES π
- Be careful when declaring args to
funcif they are notlongβ both args will occupysizeof(long)bytes in the arglist. like, they're thicc, they take up space, respect it π - If
FALSEis returned by a condition handler, and there is anany_otherhandler in the same block, theany_otherhandler will be invoked (only once, since it too may returnFALSE). - To revert a condition handler simply use
NULLasfunc. bye bye handler π SIGBLK, defined in<schily/sigblk.h>, must be included.handlecond()is frequently used withlongjmp()andsetjmp().- Eah function which calls
handlecond()must callunhandlecond()before it returns. Otherwise the return will fail or cause a core dump.
π«Ά yes, that typo is in the original ("Eah"). it's iconic, we keep it. and yes β forget the unhandlecond() and you get a core dump. not cute. do not do this.
π₯ BUGS π₯
handlecond()makes the framepointer odd, to mark the current stack frame.- This confuses programs like
adb(1)anddbx(1)because the debuggers scan the stack frame to get the call stack.
π so your debugger's gonna be confused by the funky framepointer. that's the trade, bestie. the odd framepointer is the marker, the debuggers just weren't ready for it.
okay and that's the whole vibe π β Joerg Schilling, dated 2022/09/09, page HANDLECOND(3), from SchilyΒ΄s LIBRARY FUNCTIONS. go forth and handle your conditions, bestie πβ¨π¦
π¦ where this page comes from
- opensuse-leap 16.0: libschily-devel-doc 2022.10.16-160000.2.2 Β· CDDL-1.0
- Copyright 1985-2020 J. Schilling
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms