diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/dl.h | 14 | ||||
-rw-r--r-- | common/err.h | 14 | ||||
-rw-r--r-- | common/file.h | 19 | ||||
-rw-r--r-- | common/str.h | 4 |
4 files changed, 47 insertions, 4 deletions
diff --git a/common/dl.h b/common/dl.h new file mode 100644 index 0000000..143b422 --- /dev/null +++ b/common/dl.h @@ -0,0 +1,14 @@ +#ifndef _COMMON_DL_H_ +#define _COMMON_DL_H_ + +#include <dlfcn.h> +#include "err.h" + +inline static void check_dlerror() +{ + char *err = dlerror(); + if (err) + error("library error: %s\n", err); +} + +#endif diff --git a/common/err.h b/common/err.h index 1dccbf9..b9faf11 100644 --- a/common/err.h +++ b/common/err.h @@ -1,5 +1,5 @@ -#ifndef _ERR_H_ -#define _ERR_H_ +#ifndef _COMMON_ERR_H_ +#define _COMMON_ERR_H_ #include <stdio.h> #include <stdlib.h> @@ -14,4 +14,14 @@ static inline void error(const char *format, ...) exit(1); } +static inline void syserror(const char *call, FILE *file) +{ + perror(call); + + if (file) + fclose(file); + + exit(1); +} + #endif diff --git a/common/file.h b/common/file.h new file mode 100644 index 0000000..c5e8036 --- /dev/null +++ b/common/file.h @@ -0,0 +1,19 @@ +#ifndef _COMMON_FILE_H_ +#define _COMMON_FILE_H_ + +#include <stdio.h> +#include <stdbool.h> + +inline static bool file_exists(const char *filename) +{ + FILE *f = fopen(filename, "r"); + + if (f) { + fclose(f); + return true; + } + + return false; +} + +#endif diff --git a/common/str.h b/common/str.h index b0baa37..fc5f587 100644 --- a/common/str.h +++ b/common/str.h @@ -1,5 +1,5 @@ -#ifndef _UTIL_H_ -#define _UTIL_H_ +#ifndef _COMMON_STR_H_ +#define _COMMON_STR_H_ #include <stdio.h> #include <stdarg.h> |