mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-22 05:00:08 +02:00
libreboot-utils: unified error handling
i now use a singleton hook function per program: nvmutil, mkhtemp and lottery call this at the startup of your program: (void) errhook(exit_cleanup); then provide that function. make it static, so that each program has its own version. if you're writing a program that handles lots of files for example, and you want to do certain cleanup on exit (including error exit), this can be quite useful. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
#include <stdlib.h>
|
||||
#include "include/common.h"
|
||||
|
||||
static void
|
||||
exit_cleanup(void);
|
||||
|
||||
static void
|
||||
spew_buf(const void *data, size_t len);
|
||||
|
||||
@@ -22,6 +25,8 @@ main(int argc, char **argv)
|
||||
(void) argc, (void) argv;
|
||||
xpledgex("stdio", NULL);
|
||||
|
||||
(void) errhook(exit_cleanup);
|
||||
|
||||
buf = mkrbuf(BUFSIZ + 1);
|
||||
if (!memcmp(buf, buf + (BUFSIZ >> 1), BUFSIZ >> 1))
|
||||
same = 1;
|
||||
@@ -73,3 +78,9 @@ spew_buf(const void *data, size_t len)
|
||||
|
||||
printf("%08zx\n", len);
|
||||
}
|
||||
|
||||
static void
|
||||
exit_cleanup(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user