summaryrefslogtreecommitdiff
path: root/lib/error.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-05-14 21:43:02 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-05-14 21:43:02 -0400
commite735ad6710a82604a206ad29f6cbcdd7dc4b024c (patch)
tree5fe8eebbb7a2bff20bb71bd2368955356979e0a2 /lib/error.c
parentsync (diff)
downloadlazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.tar.gz
lazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.tar.bz2
lazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.zip
refactor and add su
Diffstat (limited to 'lib/error.c')
-rw-r--r--lib/error.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/error.c b/lib/error.c
index 67828c9..0b55edb 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -1,17 +1,29 @@
-#include "error.h"
+#include "lslib.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
extern char* cmd;
+void die (void) {
+ exit (EXIT_FAILURE);
+}
+
void error_s(const char *format, ...) {
va_list list;
va_start(list, format);
fprintf(stderr, "%s: ", cmd);
vfprintf(stderr, format, list);
+
+ if (errno != 0) {
+ fprintf(stderr, ": %s", strerror(errno));
+ errno = 0;
+ }
+
fprintf(stderr, "\n");
}
@@ -21,8 +33,15 @@ void error(const char *format, ...) {
fprintf(stderr, "%s: ", cmd);
vfprintf(stderr, format, list);
+
+ if (errno != 0) {
+ fprintf(stderr, ": %s", strerror(errno));
+ errno = 0;
+ }
+
fprintf(stderr, "\n");
- exit(EXIT_FAILURE);
+
+ die();
}
void output(const char *format, ...) {