]> git.mdlowis.com Git - proto/labwc.git/commitdiff
log: add die() for convenience
authorJohan Malm <jgm323@gmail.com>
Fri, 23 Oct 2020 19:23:56 +0000 (20:23 +0100)
committerJohan Malm <jgm323@gmail.com>
Fri, 23 Oct 2020 19:23:56 +0000 (20:23 +0100)
include/common/log.h
src/common/log.c

index b2ae2efd16dd22a1bb7ea5fd9931aaee24241641..e3beb8cb935113bc130f92e71f8fd7ce5344069e 100644 (file)
@@ -11,4 +11,9 @@ void info(const char *msg, ...);
  */
 void warn(const char *err, ...);
 
+/**
+ * die - print fatal message and exit()
+ */
+void die(const char *err, ...);
+
 #endif /* __LABWC_LOG_H */
index 566c0d7b65f89ff10292cd07ea05f2cf57757ee6..b9986fb7906ba3910e935422c742b0d8190361c2 100644 (file)
@@ -32,3 +32,15 @@ warn(const char *err, ...)
        fprintf(stderr, LABWC_COLOR_RESET);
        fprintf(stderr, "\n");
 }
+
+void
+die(const char *err, ...)
+{
+       va_list params;
+       fprintf(stderr, "[labwc] fatal: ");
+       va_start(params, err);
+       vfprintf(stderr, err, params);
+       va_end(params);
+       fprintf(stderr, "\n");
+       exit(EXIT_FAILURE);
+}