]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
musl-legacy-error: Add recipe
authorKhem Raj <raj.khem@gmail.com>
Fri, 22 Sep 2023 21:05:06 +0000 (14:05 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 26 Sep 2023 09:35:07 +0000 (10:35 +0100)
This adds glibc error() API implementation which is needed by few
packages still.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/conf/distro/include/maintainers.inc
meta/recipes-core/musl/musl-legacy-error.bb [new file with mode: 0644]
meta/recipes-core/musl/musl-legacy-error/error.h [new file with mode: 0644]

index 7697324335f06a8e1f29e3b8d2dde36ba80a23ac..c583a7e2ac017b31d378b0b9595414cf10ce85e9 100644 (file)
@@ -531,6 +531,7 @@ RECIPE_MAINTAINER:pn-mtd-utils = "Denys Dmytriyenko <denis@denix.org>"
 RECIPE_MAINTAINER:pn-mtdev = "Anuj Mittal <anuj.mittal@intel.com>"
 RECIPE_MAINTAINER:pn-mtools = "Anuj Mittal <anuj.mittal@intel.com>"
 RECIPE_MAINTAINER:pn-musl = "Khem Raj <raj.khem@gmail.com>"
+RECIPE_MAINTAINER:pn-musl-legacy-error = "Khem Raj <raj.khem@gmail.com>"
 RECIPE_MAINTAINER:pn-musl-locales = "Khem Raj <raj.khem@gmail.com>"
 RECIPE_MAINTAINER:pn-musl-obstack = "Khem Raj <raj.khem@gmail.com>"
 RECIPE_MAINTAINER:pn-musl-utils = "Khem Raj <raj.khem@gmail.com>"
diff --git a/meta/recipes-core/musl/musl-legacy-error.bb b/meta/recipes-core/musl/musl-legacy-error.bb
new file mode 100644 (file)
index 0000000..5ce5a23
--- /dev/null
@@ -0,0 +1,26 @@
+# Copyright (C) 2023 Khem Raj <raj.khem@gmail.com>
+# 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 (file)
index 0000000..9a4e1f8
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef _ERROR_H_
+#define _ERROR_H_
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#warning usage of non-standard #include <error.h> 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_ */