1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ 2 /* 3 * formatted error message for NOLIBC 4 * Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net> 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 17 static __attribute__((unused)) 18 void 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 25 static __attribute__((unused)) 26 void 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 33 static __attribute__((unused)) 34 void 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 43 static __attribute__((unused)) 44 void 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 53 static __attribute__((noreturn, unused)) 54 void verr(int eval, const char *fmt, va_list args) 55 { 56 vwarn(fmt, args); 57 exit(eval); 58 } 59 60 static __attribute__((noreturn, unused)) 61 void verrx(int eval, const char *fmt, va_list args) 62 { 63 warnx(fmt, args); 64 exit(eval); 65 } 66 67 static __attribute__((noreturn, unused)) 68 void 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 77 static __attribute__((noreturn, unused)) 78 void 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 */ 88