From c7fdb5aca58f1a9d37905588c61cafaf585e9ff9 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Fri, 22 Sep 2023 14:05:06 -0700 Subject: musl-legacy-error: Add recipe This adds glibc error() API implementation which is needed by few packages still. (From OE-Core rev: c3f0f00a8dcc76ece298cf4debf1ca71f930ec57) Signed-off-by: Khem Raj Signed-off-by: Alexandre Belloni Signed-off-by: Richard Purdie --- meta/recipes-core/musl/musl-legacy-error.bb | 26 ++++++++++ meta/recipes-core/musl/musl-legacy-error/error.h | 60 ++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 meta/recipes-core/musl/musl-legacy-error.bb create mode 100644 meta/recipes-core/musl/musl-legacy-error/error.h (limited to 'meta/recipes-core/musl') diff --git a/meta/recipes-core/musl/musl-legacy-error.bb b/meta/recipes-core/musl/musl-legacy-error.bb new file mode 100644 index 0000000000..5ce5a233ab --- /dev/null +++ b/meta/recipes-core/musl/musl-legacy-error.bb @@ -0,0 +1,26 @@ +# Copyright (C) 2023 Khem Raj +# Released under the MIT license (see COPYING.MIT for the terms) + +SUMMARY = "error API GNU extention implementation" +LICENSE = "BSD-2-Clause" +LIC_FILES_CHKSUM = "file://error.h;beginline=1;md5=2ee396b23e8507fbf8f98af0471a77c6" +SECTION = "devel" + +SRC_URI = "file://error.h" + +do_configure[noexec] = "1" +do_compile[noexec] = "1" + +INHIBIT_DEFAULT_DEPS = "1" + +S = "${WORKDIR}" + +do_install() { + install -Dm 0644 ${S}/error.h -t ${D}${includedir} +} +# +# We will skip parsing for non-musl systems +# +COMPATIBLE_HOST = ".*-musl.*" +DEV_PKG_DEPENDENCY = "" +RRECOMMENDS:${PN}-dbg = "${PN}-dev (= ${EXTENDPKGV})" diff --git a/meta/recipes-core/musl/musl-legacy-error/error.h b/meta/recipes-core/musl/musl-legacy-error/error.h new file mode 100644 index 0000000000..9a4e1f8d00 --- /dev/null +++ b/meta/recipes-core/musl/musl-legacy-error/error.h @@ -0,0 +1,60 @@ +#ifndef _ERROR_H_ +#define _ERROR_H_ + +#include +#include +#include +#include +#include + +#warning usage of non-standard #include is deprecated + +static unsigned int error_message_count = 0; + +static inline void error(int status, int errnum, const char* format, ...) +{ + /* should be fflush(stdout), but that's unspecified if stdout has been closed; + * stick with fflush(NULL) for simplicity (glibc checks if the fd is still valid) */ + fflush(NULL); + + va_list ap; + fprintf(stderr, "%s: ", program_invocation_name); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + if (errnum) + fprintf(stderr, ": %s", strerror(errnum)); + fprintf(stderr, "\n"); + error_message_count++; + if (status) + exit(status); +} + +static int error_one_per_line = 0; + +static inline void error_at_line(int status, int errnum, const char *filename, + unsigned int linenum, const char *format, ...) +{ + va_list ap; + if (error_one_per_line) { + static const char *old_filename; + static int old_linenum; + if (linenum == old_linenum && filename == old_filename) + return; + old_filename = filename; + old_linenum = linenum; + } + fprintf(stderr, "%s: %s:%u: ", program_invocation_name, filename, linenum); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + if (errnum) + fprintf(stderr, ": %s", strerror(errnum)); + fprintf(stderr, "\n"); + error_message_count++; + if (status) + exit(status); +} + + +#endif /* _ERROR_H_ */ -- cgit v1.2.3-54-g00ecf