daeca3892e
Portable ELF tooling (elfutils/libelf, needed by Mesa's radeonsi driver) relies on several standard headers and functions Red Bear's relibc lacked: - <byteswap.h>: bswap_16/32/64 (compiler builtins). - <error.h>: GNU error()/error_at_line() (inline). - <libintl.h>: gettext family as the identity map (catalog-less system; matches glibc's no-catalog fallback behaviour). - <ar.h>: Unix archive struct/magic (header-only). - <search.h> + src/header/search: POSIX tsearch/tfind/tdelete/twalk + GNU tdestroy, implemented as an unbalanced BST (conforming; POSIX mandates no balancing). - string: mempcpy (memcpy returning end) and rawmemchr (unbounded memchr). All complete implementations, no stubs. Additive (no ABI break), so existing sysroot binaries are unaffected.
61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
/* error.h — GNU-style error reporting.
|
|
*
|
|
* Red Bear OS / relibc. Mirrors glibc <error.h>: error() and error_at_line()
|
|
* print the program name (best effort), a formatted message, and optionally a
|
|
* strerror() of errnum to stderr, then exit() when status is non-zero. Provided
|
|
* as complete inline implementations so portable tooling (elfutils/libelf,
|
|
* GNU-style CLIs) that includes <error.h> builds and behaves correctly.
|
|
*/
|
|
#ifndef _ERROR_H
|
|
#define _ERROR_H 1
|
|
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
static inline void error(int __status, int __errnum, const char *__format, ...) {
|
|
va_list __ap;
|
|
fflush(stdout);
|
|
va_start(__ap, __format);
|
|
vfprintf(stderr, __format, __ap);
|
|
va_end(__ap);
|
|
if (__errnum != 0) {
|
|
fprintf(stderr, ": %s", strerror(__errnum));
|
|
}
|
|
fputc('\n', stderr);
|
|
if (__status != 0) {
|
|
exit(__status);
|
|
}
|
|
}
|
|
|
|
static inline void error_at_line(int __status, int __errnum,
|
|
const char *__fname, unsigned int __lineno,
|
|
const char *__format, ...) {
|
|
va_list __ap;
|
|
fflush(stdout);
|
|
if (__fname != NULL) {
|
|
fprintf(stderr, "%s:%u: ", __fname, __lineno);
|
|
}
|
|
va_start(__ap, __format);
|
|
vfprintf(stderr, __format, __ap);
|
|
va_end(__ap);
|
|
if (__errnum != 0) {
|
|
fprintf(stderr, ": %s", strerror(__errnum));
|
|
}
|
|
fputc('\n', stderr);
|
|
if (__status != 0) {
|
|
exit(__status);
|
|
}
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* error.h */
|