diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-14 23:24:00 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-15 00:02:54 -0600 |
commit | b087b07c9649b7e4398093720ebcf96f205c2c49 (patch) | |
tree | acebc421da0f1dcf3325178d6569bfd57d23abec /libgcompat | |
parent | 900ab571ba496f73b1e66204f8c66560afda29e6 (diff) | |
download | gcompat-b087b07c9649b7e4398093720ebcf96f205c2c49.tar.gz gcompat-b087b07c9649b7e4398093720ebcf96f205c2c49.tar.bz2 gcompat-b087b07c9649b7e4398093720ebcf96f205c2c49.tar.xz gcompat-b087b07c9649b7e4398093720ebcf96f205c2c49.zip |
error: Implement the error function
This follows the exceptionally-detailed functional description in the
manual page.
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'libgcompat')
-rw-r--r-- | libgcompat/error.c | 27 |
1 files changed, 27 insertions, 0 deletions
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 <errno.h> /* program_invocation_name */ +#include <stdarg.h> /* va_list, va_start, va_end */ +#include <stdio.h> /* fflush, fputc, fputs, stderr, stdout, vfprintf */ +#include <string.h> /* 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); + } +} |