From 754ab792e43ab4b95350fee2f5e841186af13653 Mon Sep 17 00:00:00 2001 From: Tharre Date: Tue, 29 Jul 2014 00:51:25 +0200 Subject: Add filepath.c, refactor out parse_shebang() and rewrite most of the error checking code to use predefined error macros --- src/util.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 86310fc..789a404 100644 --- a/src/util.h +++ b/src/util.h @@ -1,24 +1,34 @@ #ifndef __RUTIL_H__ #define __RUTIL_H__ -#include -#include +#include #include - +/* standard error messages */ #define _PROGNAME "redo" +#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 safe_malloc(size) safe_malloc_(size, _FILENAME, __LINE__) #define safe_realloc(ptr, size) safe_realloc_(ptr, size, _FILENAME, __LINE__) -#define safe_fopen(path, mode) safe_fopen_(path, mode, _FILENAME, __LINE__) #define safe_strdup(str) safe_strdup_(str, _FILENAME, __LINE__) -extern void *safe_malloc_(size_t size, const char *file, unsigned int line); -extern void *safe_realloc_(void *ptr, size_t size, const char *file, unsigned int 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 FILE *safe_fopen_(const char *path, const char *mode, - const char *file, unsigned int line); extern char *concat(size_t count, ...); -extern char *xbasename(const char *path); #endif -- cgit v1.2.3-70-g09d2