diff options
author | Fabian Groffen | 2011-01-25 22:44:52 +0100 |
---|---|---|
committer | Karel Zak | 2011-02-14 17:45:24 +0100 |
commit | eb76ca98b0733754d7e9a40f754e89b50af2bf06 (patch) | |
tree | f2becaf31f77a664256273e6ec6772904422ac53 /include | |
parent | sfdisk: rename warn to my_warn (diff) | |
download | kernel-qcow2-util-linux-eb76ca98b0733754d7e9a40f754e89b50af2bf06.tar.gz kernel-qcow2-util-linux-eb76ca98b0733754d7e9a40f754e89b50af2bf06.tar.xz kernel-qcow2-util-linux-eb76ca98b0733754d7e9a40f754e89b50af2bf06.zip |
build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx. This also means the err.h header
doesn't exist. Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/c.h | 47 | ||||
-rw-r--r-- | include/xalloc.h | 1 |
2 files changed, 47 insertions, 1 deletions
diff --git a/include/c.h b/include/c.h index 815463881..0db8b2b59 100644 --- a/include/c.h +++ b/include/c.h @@ -6,6 +6,15 @@ #define UTIL_LINUX_C_H #include <limits.h> +#include <stdint.h> +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <errno.h> + +#ifdef HAVE_ERR_H +# include <err.h> +#endif /* * Compiler specific stuff @@ -95,6 +104,44 @@ #endif +#ifndef HAVE_ERR_H +static inline void +errmsg(char doexit, int excode, char adderr, const char *fmt, ...) +{ + fprintf(stderr, "%s: ", program_invocation_short_name); + if (fmt != NULL) { + va_list argp; + va_start(argp, fmt); + vfprintf(stderr, fmt, argp); + va_end(argp); + if (adderr) + fprintf(stderr, ": "); + } + if (adderr) + fprintf(stderr, "%s", strerror(errno)); + fprintf(stderr, "\n"); + if (doexit) + exit(excode); +} + +#ifndef HAVE_ERR +# define err(E, FMT...) errmsg(1, E, 1, FMT) +#endif + +#ifndef HAVE_ERRX +# define errx(E, FMT...) errmsg(1, E, 0, FMT) +#endif + +#ifndef HAVE_WARN +# define warn(FMT...) errmsg(0, 0, 1, FMT) +#endif + +#ifndef HAVE_WARNX +# define warnx(FMT...) errmsg(0, 0, 0, FMT) +#endif +#endif /* !HAVE_ERR_H */ + + static inline __attribute__((const)) int is_power_of_2(unsigned long num) { return (num != 0 && ((num & (num - 1)) == 0)); diff --git a/include/xalloc.h b/include/xalloc.h index 841333c30..0e9ee3248 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -11,7 +11,6 @@ #define UTIL_LINUX_XALLOC_H #include <stdlib.h> -#include <err.h> #include <string.h> #include "c.h" |