mirror of
https://github.com/FAUSheppy/colorredstderr-mirror
synced 2025-12-11 09:28:33 +01:00
Hook BSD err(), errx(), warn(), warnx(), etc. functions.
err(), errx(), warn(), warnx(), verr(), verrx(), vwarn(), vwarnx() are hooked.
This commit is contained in:
@@ -38,6 +38,9 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_ERR_H
|
||||
# include <err.h>
|
||||
#endif
|
||||
#ifdef HAVE_ERROR_H
|
||||
# include <error.h>
|
||||
#endif
|
||||
@@ -265,6 +268,33 @@ HOOK_FD2(int, __overflow, f->_fileno, _IO_FILE *, f, int, ch)
|
||||
HOOK_VOID1(void, perror, STDERR_FILENO,
|
||||
char const *, s)
|
||||
|
||||
/* err(3), non standard BSD extension */
|
||||
#ifdef HAVE_ERR_H
|
||||
HOOK_VAR_VOID2(void, err, STDERR_FILENO, verr,
|
||||
int, eval, char const *, fmt)
|
||||
HOOK_VAR_VOID2(void, errx, STDERR_FILENO, verrx,
|
||||
int, eval, char const *, fmt)
|
||||
HOOK_VAR_VOID1(void, warn, STDERR_FILENO, vwarn,
|
||||
char const *, fmt)
|
||||
HOOK_VAR_VOID1(void, warnx, STDERR_FILENO, vwarnx,
|
||||
char const *, fmt)
|
||||
HOOK_FUNC_SIMPLE3(void, verr, int, eval, const char *, fmt, va_list, args) {
|
||||
/* Can't use verr() directly as it terminates the process which prevents
|
||||
* the post string from being printed. */
|
||||
vwarn(fmt, args);
|
||||
exit(eval);
|
||||
}
|
||||
HOOK_FUNC_SIMPLE3(void, verrx, int, eval, const char *, fmt, va_list, args) {
|
||||
/* See verr(). */
|
||||
vwarnx(fmt, args);
|
||||
exit(eval);
|
||||
}
|
||||
HOOK_VOID2(void, vwarn, STDERR_FILENO,
|
||||
char const *, fmt, va_list, args)
|
||||
HOOK_VOID2(void, vwarnx, STDERR_FILENO,
|
||||
char const *, fmt, va_list, args)
|
||||
#endif
|
||||
|
||||
/* error(3), non-standard GNU extension */
|
||||
#ifdef HAVE_ERROR_H
|
||||
static void error_vararg(int status, int errnum,
|
||||
|
||||
@@ -115,6 +115,9 @@
|
||||
static type (*real_ ## name)(type1, type2, ...); \
|
||||
type name(type1 arg1, type2 arg2, ...)
|
||||
|
||||
#define HOOK_FUNC_SIMPLE3(type, name, type1, arg1, type2, arg2, type3, arg3) \
|
||||
type name(type1 arg1, type2 arg2, type3 arg3)
|
||||
|
||||
#define HOOK_VOID1(type, name, fd, type1, arg1) \
|
||||
static type (*real_ ## name)(type1); \
|
||||
type name(type1 arg1) { \
|
||||
@@ -122,6 +125,35 @@
|
||||
real_ ## name(arg1); \
|
||||
_HOOK_POST_FD_(fd) \
|
||||
}
|
||||
#define HOOK_VOID2(type, name, fd, type1, arg1, type2, arg2) \
|
||||
static type (*real_ ## name)(type1, type2); \
|
||||
type name(type1 arg1, type2 arg2) { \
|
||||
_HOOK_PRE_FD_(type, name, fd) \
|
||||
real_ ## name(arg1, arg2); \
|
||||
_HOOK_POST_FD_(fd) \
|
||||
}
|
||||
#define HOOK_VOID3(type, name, fd, type1, arg1, type2, arg2, type3, arg3) \
|
||||
static type (*real_ ## name)(type1, type2, type3); \
|
||||
type name(type1 arg1, type2 arg2, type3 arg3) { \
|
||||
_HOOK_PRE_FD_(type, name, fd) \
|
||||
real_ ## name(arg1, arg2, arg3); \
|
||||
_HOOK_POST_FD_(fd) \
|
||||
}
|
||||
|
||||
#define HOOK_VAR_VOID1(type, name, fd, func, type1, arg1) \
|
||||
type name(type1 arg1, ...) { \
|
||||
va_list ap; \
|
||||
va_start(ap, arg1); \
|
||||
func(arg1, ap); \
|
||||
va_end(ap); \
|
||||
}
|
||||
#define HOOK_VAR_VOID2(type, name, fd, func, type1, arg1, type2, arg2) \
|
||||
type name(type1 arg1, type2 arg2, ...) { \
|
||||
va_list ap; \
|
||||
va_start(ap, arg2); \
|
||||
func(arg1, arg2, ap); \
|
||||
va_end(ap); \
|
||||
}
|
||||
|
||||
#define HOOK_FD2(type, name, fd, type1, arg1, type2, arg2) \
|
||||
static type (*real_ ## name)(type1, type2); \
|
||||
|
||||
Reference in New Issue
Block a user