mirror of
https://github.com/fluencelabs/musl
synced 2025-06-30 15:11:55 +00:00
support the nonstandard err.h interfaces
note that unlike the originals, these do not print the program name/argv[0] because we have not saved it anywhere. this could be changed in __libc_start_main if desired.
This commit is contained in:
24
include/err.h
Normal file
24
include/err.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef _ERR_H
|
||||||
|
#define _ERR_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void warn(const char *, ...);
|
||||||
|
void vwarn(const char *, va_list);
|
||||||
|
void warnx(const char *, ...);
|
||||||
|
void vwarnx(const char *, va_list);
|
||||||
|
|
||||||
|
void err(int, const char *, ...);
|
||||||
|
void verr(int, const char *, va_list);
|
||||||
|
void errx(int, const char *, ...);
|
||||||
|
void verrx(int, const char *, va_list);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
60
src/linux/err.c
Normal file
60
src/linux/err.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <err.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void vwarn(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
perror("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void vwarnx(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
putc('\n', stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void verr(int status, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
vwarn(fmt, ap);
|
||||||
|
exit(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void verrx(int status, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
vwarnx(fmt, ap);
|
||||||
|
exit(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void warn(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vwarn(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void warnx(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vwarnx(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void err(int status, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
verr(status, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void errx(int status, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
verrx(status, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
Reference in New Issue
Block a user