diff --git a/Makefile b/Makefile index a433074dd7..2f68d9642e 100644 --- a/Makefile +++ b/Makefile @@ -1325,6 +1325,7 @@ $(out)/musl/src/math/llroundl.o: conf-opt := $(conf-opt) -O0 musl += misc/a64l.o libc += misc/basename.o musl += misc/dirname.o +libc += misc/error.o libc += misc/ffs.o musl += misc/get_current_dir_name.o libc += misc/gethostid.o diff --git a/libc/misc/error.c b/libc/misc/error.c new file mode 100644 index 0000000000..9995b6784f --- /dev/null +++ b/libc/misc/error.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2019 Waldemar Kozaczuk + * + * This work is open source software, licensed under the terms of the + * BSD license as described in the LICENSE file in the top-level directory. + */ + +#include +#include +#include +#include + +extern char *program_invocation_name; + +void +error (int status, int errnum, const char *message, ...) +{ + fflush(stdout); + + fprintf(stderr, "%s: ", program_invocation_name); + + va_list args; + int ret; + va_start(args, message); + ret = vfprintf(stderr, message, args); + va_end(args); + + if (errnum) { + fprintf(stderr, ": %s", strerror(errnum)); + } + + fprintf(stderr, "\n" ); + + if (status) { + exit(status); + } +}