projects/linux·blob master · refs

87 lines · 1.6 KiB

1/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2/*
3 * formatted error message for NOLIBC
4 * Copyright (C) 2026 Thomas Weißschuh <[email protected]>
5 */
6
7/* make sure to include all global symbols */
8#include "nolibc.h"
9
10#ifndef _NOLIBC_ERR_H
11#define _NOLIBC_ERR_H
12
13#include "errno.h"
14#include "stdarg.h"
15#include "sys.h"
16
17static __attribute__((unused))
18void vwarn(const char *fmt, va_list args)
19{
20 fprintf(stderr, "%s: ", program_invocation_short_name);
21 vfprintf(stderr, fmt, args);
22 fprintf(stderr, ": %m\n");
23}
24
25static __attribute__((unused))
26void vwarnx(const char *fmt, va_list args)
27{
28 fprintf(stderr, "%s: ", program_invocation_short_name);
29 vfprintf(stderr, fmt, args);
30 fprintf(stderr, "\n");
31}
32
33static __attribute__((unused))
34void warn(const char *fmt, ...)
35{
36 va_list args;
37
38 va_start(args, fmt);
39 vwarn(fmt, args);
40 va_end(args);
41}
42
43static __attribute__((unused))
44void warnx(const char *fmt, ...)
45{
46 va_list args;
47
48 va_start(args, fmt);
49 vwarnx(fmt, args);
50 va_end(args);
51}
52
53static __attribute__((noreturn, unused))
54void verr(int eval, const char *fmt, va_list args)
55{
56 vwarn(fmt, args);
57 exit(eval);
58}
59
60static __attribute__((noreturn, unused))
61void verrx(int eval, const char *fmt, va_list args)
62{
63 vwarnx(fmt, args);
64 exit(eval);
65}
66
67static __attribute__((noreturn, unused))
68void err(int eval, const char *fmt, ...)
69{
70 va_list args;
71
72 va_start(args, fmt);
73 verr(eval, fmt, args);
74 va_end(args);
75}
76
77static __attribute__((noreturn, unused))
78void errx(int eval, const char *fmt, ...)
79{
80 va_list args;
81
82 va_start(args, fmt);
83 verrx(eval, fmt, args);
84 va_end(args);
85}
86
87#endif /* _NOLIBC_ERR_H */