From: Khem Raj Date: Fri, 22 Sep 2023 21:05:06 +0000 (-0700) Subject: musl-legacy-error: Add recipe X-Git-Tag: yocto-5.2~5037 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c3f0f00a8dcc76ece298cf4debf1ca71f930ec57;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git musl-legacy-error: Add recipe This adds glibc error() API implementation which is needed by few packages still. Signed-off-by: Khem Raj Signed-off-by: Alexandre Belloni Signed-off-by: Richard Purdie --- diff --git a/meta/conf/distro/include/maintainers.inc b/meta/conf/distro/include/maintainers.inc index 7697324335f..c583a7e2ac0 100644 --- a/meta/conf/distro/include/maintainers.inc +++ b/meta/conf/distro/include/maintainers.inc @@ -531,6 +531,7 @@ RECIPE_MAINTAINER:pn-mtd-utils = "Denys Dmytriyenko " RECIPE_MAINTAINER:pn-mtdev = "Anuj Mittal " RECIPE_MAINTAINER:pn-mtools = "Anuj Mittal " RECIPE_MAINTAINER:pn-musl = "Khem Raj " +RECIPE_MAINTAINER:pn-musl-legacy-error = "Khem Raj " RECIPE_MAINTAINER:pn-musl-locales = "Khem Raj " RECIPE_MAINTAINER:pn-musl-obstack = "Khem Raj " RECIPE_MAINTAINER:pn-musl-utils = "Khem Raj " 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 00000000000..5ce5a233ab1 --- /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 00000000000..9a4e1f8d006 --- /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_ */