aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-05-07 15:12:28 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-05-07 15:12:28 -0700
commite0052b139483e67e5dfe7635658516ee1fabaa1f (patch)
treed6b5f1200af5f3bf3534ac267ce570cca881e6ac /utils.h
parent34cb45567ea01b175e59b039d425997883729f33 (diff)
Code cleanup
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h25
1 files changed, 6 insertions, 19 deletions
diff --git a/utils.h b/utils.h
index 0703912..7fe1de9 100644
--- a/utils.h
+++ b/utils.h
@@ -9,6 +9,7 @@
#ifndef FILE_UTILS__H
#define FILE_UTILS__H
+#include <err.h>
#include <stdio.h>
#include <string.h>
@@ -16,6 +17,11 @@
#define streq(a,b) (strcmp(a,b)==0)
#endif
+#define new(t) memcheck(calloc(1, sizeof(t)))
+#define xcalloc(a,b) memcheck(calloc(a,b))
+#define xrealloc(a,b) memcheck(realloc(a,b))
+#define clean_err(...) do { cleanup(); err(1, __VA_ARGS__); } while (0)
+
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#define MIN(a,b) ((a) > (b) ? (b) : (a))
@@ -32,25 +38,6 @@
#define ctime(s) (s).st_ctim
#endif
-// Error reporting macros:
-#define err(...) do { \
- cleanup(); \
- fprintf(stderr, __VA_ARGS__); \
- if (errno) fprintf(stderr, "\n%s", strerror(errno)); \
- fprintf(stderr, "\n"); \
- exit(EXIT_FAILURE); \
-} while (0)
-
-#define warn(...) do { \
- move_cursor(tty_out, 0, winsize.ws_row-1); \
- fputs("\033[41;33;1m", tty_out); \
- fprintf(tty_out, __VA_ARGS__); \
- fputs(" Press any key to continue...\033[0m ", tty_out); \
- fflush(tty_out); \
- while (bgetkey(tty_in, NULL, NULL) == -1) usleep(100); \
- bb->dirty = 1; \
-} while (0)
-
// Entry macros
#define IS_SELECTED(e) (((e)->selected.atme) != NULL)
#define IS_VIEWED(e) ((e)->index >= 0)