From 0f1a22174fc7c6a0767617974640d521074174d5 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 28 Mar 2026 06:53:37 +0000 Subject: 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 --- util/libreboot-utils/lib/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'util/libreboot-utils/lib/file.c') diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c index 3b3e57d8..fbb4e53f 100644 --- a/util/libreboot-utils/lib/file.c +++ b/util/libreboot-utils/lib/file.c @@ -73,16 +73,16 @@ void xopen(int *fd_ptr, const char *path, int flags, struct stat *st) { if ((*fd_ptr = open(path, flags)) < 0) - err_no_cleanup(0, errno, "%s", path); + err_exit(errno, "%s", path); if (fstat(*fd_ptr, st) < 0) - err_no_cleanup(0, errno, "%s: stat", path); + err_exit(errno, "%s: stat", path); if (!S_ISREG(st->st_mode)) - err_no_cleanup(0, errno, "%s: not a regular file", path); + err_exit(errno, "%s: not a regular file", path); if (lseek_on_eintr(*fd_ptr, 0, SEEK_CUR, 1, 1) == (off_t)-1) - err_no_cleanup(0, errno, "%s: file not seekable", path); + err_exit(errno, "%s: file not seekable", path); } int -- cgit v1.2.1