From b087b07c9649b7e4398093720ebcf96f205c2c49 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 14 Jan 2018 23:24:00 -0600 Subject: error: Implement the error function This follows the exceptionally-detailed functional description in the manual page. Signed-off-by: Samuel Holland --- Makefile | 1 + libgcompat/error.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 libgcompat/error.c diff --git a/Makefile b/Makefile index b5fda64..2ff1495 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ LIBGCOMPAT_INCLUDE = \ libgcompat/alias.h LIBGCOMPAT_SRC = \ libgcompat/dlfcn.c \ + libgcompat/error.c \ libgcompat/execinfo.c \ libgcompat/gnulib.c \ libgcompat/grp.c \ diff --git a/libgcompat/error.c b/libgcompat/error.c new file mode 100644 index 0000000..c759b19 --- /dev/null +++ b/libgcompat/error.c @@ -0,0 +1,27 @@ +#define _GNU_SOURCE /* program_invocation_name */ +#include /* program_invocation_name */ +#include /* va_list, va_start, va_end */ +#include /* fflush, fputc, fputs, stderr, stdout, vfprintf */ +#include /* strerror */ + +/** + * Print an error message. + * + * LSB 5.0: LSB-Core-generic/baselib-error-n.html + */ +void error(int status, int errnum, const char *format, ...) +{ + va_list ap; + + fflush(stdout); + fputs(program_invocation_name, stderr); + fputs(": ", stderr); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + if (errnum != 0) { + fputs(": ", stderr); + fputs(strerror(errnum), stderr); + fputc('\n', stderr); + } +} -- cgit v1.2.3-70-g09d2