diff options
Diffstat (limited to 'utils.h')
| -rw-r--r-- | utils.h | 25 |
1 files changed, 6 insertions, 19 deletions
@@ -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) |
