summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/musl/musl-legacy-error/error.h
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2023-09-22 14:05:06 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-09-26 10:35:28 +0100
commitc7fdb5aca58f1a9d37905588c61cafaf585e9ff9 (patch)
tree9008a47f78932f829fec6c6fed5fc21871bed9db /meta/recipes-core/musl/musl-legacy-error/error.h
parent0ccd6425db2cc91406fae14e4e5a7e4fe354ff77 (diff)
downloadpoky-c7fdb5aca58f1a9d37905588c61cafaf585e9ff9.tar.gz
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 <raj.khem@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/musl/musl-legacy-error/error.h')
-rw-r--r--meta/recipes-core/musl/musl-legacy-error/error.h60
1 files changed, 60 insertions, 0 deletions
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 @@
1#ifndef _ERROR_H_
2#define _ERROR_H_
3
4#include <stdarg.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <errno.h>
9
10#warning usage of non-standard #include <error.h> is deprecated
11
12static unsigned int error_message_count = 0;
13
14static inline void error(int status, int errnum, const char* format, ...)
15{
16 /* should be fflush(stdout), but that's unspecified if stdout has been closed;
17 * stick with fflush(NULL) for simplicity (glibc checks if the fd is still valid) */
18 fflush(NULL);
19
20 va_list ap;
21 fprintf(stderr, "%s: ", program_invocation_name);
22 va_start(ap, format);
23 vfprintf(stderr, format, ap);
24 va_end(ap);
25 if (errnum)
26 fprintf(stderr, ": %s", strerror(errnum));
27 fprintf(stderr, "\n");
28 error_message_count++;
29 if (status)
30 exit(status);
31}
32
33static int error_one_per_line = 0;
34
35static inline void error_at_line(int status, int errnum, const char *filename,
36 unsigned int linenum, const char *format, ...)
37{
38 va_list ap;
39 if (error_one_per_line) {
40 static const char *old_filename;
41 static int old_linenum;
42 if (linenum == old_linenum && filename == old_filename)
43 return;
44 old_filename = filename;
45 old_linenum = linenum;
46 }
47 fprintf(stderr, "%s: %s:%u: ", program_invocation_name, filename, linenum);
48 va_start(ap, format);
49 vfprintf(stderr, format, ap);
50 va_end(ap);
51 if (errnum)
52 fprintf(stderr, ": %s", strerror(errnum));
53 fprintf(stderr, "\n");
54 error_message_count++;
55 if (status)
56 exit(status);
57}
58
59
60#endif /* _ERROR_H_ */