aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.h
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2014-11-16 19:19:59 +0100
committerTharre <tharre3@gmail.com>2014-11-16 19:19:59 +0100
commitdf9bc5b9d048c7ecb96838123e39d5bc7c23aa18 (patch)
tree5432d5cc4a0e5a7550f7bae00964f09cb68b6361 /src/util.h
parentb4c1b2145d6a0b1ec4219847dc26877046f84e8b (diff)
downloadredo-df9bc5b9d048c7ecb96838123e39d5bc7c23aa18.tar.gz
redo-df9bc5b9d048c7ecb96838123e39d5bc7c23aa18.tar.xz
redo-df9bc5b9d048c7ecb96838123e39d5bc7c23aa18.zip
Refactor error handling system by using die()
Defined error messages have also been replaced with string literals.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h32
1 files changed, 6 insertions, 26 deletions
diff --git a/src/util.h b/src/util.h
index 500ee6e..0cac914 100644
--- a/src/util.h
+++ b/src/util.h
@@ -9,35 +9,15 @@
#ifndef __RUTIL_H__
#define __RUTIL_H__
-#include <stdbool.h>
#include <stddef.h>
-/* standard error messages */
-#define _PROGNAME "redo"
+#define DIE_HELPER(M, ...) die(M ": %s\n", __VA_ARGS__)
+#define diem(...) DIE_HELPER(__VA_ARGS__, strerror(errno))
-#define ERRM_MALLOC _PROGNAME": cannot allocate %zu bytes"
-#define ERRM_REALLOC _PROGNAME": cannot reallocate %zu bytes"
-#define ERRM_FOPEN _PROGNAME": failed to open %s"
-#define ERRM_FREAD _PROGNAME": failed to read from %s"
-#define ERRM_FCLOSE _PROGNAME": failed to close %s"
-#define ERRM_WRITE _PROGNAME": failed to write to %s"
-#define ERRM_CHDIR _PROGNAME": failed to change directory to %s"
-#define ERRM_SETENV _PROGNAME": failed to setenv %s to %s"
-#define ERRM_EXEC _PROGNAME": failed to replace child process with %s"
-#define ERRM_REMOVE _PROGNAME": failed to remove %s"
-#define ERRM_RENAME _PROGNAME": failed to rename %s to %s"
-#define ERRM_FORK _PROGNAME": failed to fork() new process"
-#define ERRM_REALPATH _PROGNAME": failed to get realpath() of %s"
-#define ERRM_STAT _PROGNAME": failed to aquire stat() information about %s"
-#define ERRM_MKDIR _PROGNAME": failed to mkdir() '%s'"
-
-#define safe_malloc(size) safe_malloc_(size, _FILENAME, __LINE__)
-#define safe_realloc(ptr, size) safe_realloc_(ptr, size, _FILENAME, __LINE__)
-#define safe_strdup(str) safe_strdup_(str, _FILENAME, __LINE__)
-
-extern void *safe_malloc_(size_t size, const char *file, unsigned line);
-extern void *safe_realloc_(void *ptr, size_t size, const char *file, unsigned line);
-extern char *safe_strdup_(const char *str, const char *file, unsigned line);
+extern void __attribute__((noreturn)) die(const char *err, ...);
+extern void *xmalloc(size_t size);
+extern void *xrealloc(void *ptr, size_t size);
+extern char *xstrdup(const char *str);
extern char *concat(size_t count, ...);
#endif