From 430bca8a0f166df268e2fa8fb207286640bd0602 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Sun, 5 Jul 2026 18:30:38 +0200 Subject: Add a sys_check routine --- src/system.c | 10 ++++++++++ src/system.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/system.c b/src/system.c index df53e99..2f95661 100644 --- a/src/system.c +++ b/src/system.c @@ -10,6 +10,16 @@ #include #include "system.h" +#include "utils.h" + +void __sys_check(int cond, const char *prefix, const char *file, int line) +{ + if (!cond) { + fprintf(stderr, "%s:%d: %s: ", file, line, prefix); + perror(""); + exit(EXIT_FAILURE); + } +} int file_exists(const char *path) { diff --git a/src/system.h b/src/system.h index 950a82a..1045153 100644 --- a/src/system.h +++ b/src/system.h @@ -4,6 +4,10 @@ /* Routines for interacting with the system, mainly executing processes and * dealing with the file system. */ +void __sys_check(int cond, const char *prefix, const char *file, int line); + +#define sys_check(COND, PREFIX) __sys_check(COND, PREFIX, __FILE__, __LINE__) + /* Used when encrypting or decrypting a file, see the copy_file_with_encryption * function. */ enum encrypt { -- cgit v1.2.3