summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-01-22 17:17:55 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-01-22 17:17:55 +0200
commitd10244248bdf2d6d98a69dd73bd5cdb187bdefe9 (patch)
tree3884104a492e564948d4515dce10334c432d6702
parent986382a0bb326167392635d6e883f3b76c7d8361 (diff)
downloadpaxutils-d10244248bdf2d6d98a69dd73bd5cdb187bdefe9.tar.gz
Implement pre-error-display hook.
* paxlib/error.c (error_hook): New global. * paxlib/paxlib.h (error_hook): New extern. (WARN, ERROR, FATAL_ERROR) (USAGE_ERROR): Call error_hook (if defined) before error().
-rw-r--r--paxlib/error.c2
-rw-r--r--paxlib/paxlib.h28
2 files changed, 26 insertions, 4 deletions
diff --git a/paxlib/error.c b/paxlib/error.c
index 56903a3..134cef3 100644
--- a/paxlib/error.c
+++ b/paxlib/error.c
@@ -21,6 +21,8 @@
#include <quote.h>
#include <quotearg.h>
+void (*error_hook) (void);
+
/* Decode MODE from its binary form in a stat structure, and encode it
into a 9-byte string STRING, terminated with a NUL. */
diff --git a/paxlib/paxlib.h b/paxlib/paxlib.h
index d0ba45b..d4251d1 100644
--- a/paxlib/paxlib.h
+++ b/paxlib/paxlib.h
@@ -32,6 +32,8 @@
#define PAXEXIT_DIFFERS 1
#define PAXEXIT_FAILURE 2
+extern void (*error_hook) (void);
+
/* Both WARN and ERROR write a message on stderr and continue processing,
however ERROR manages so tar will exit unsuccessfully. FATAL_ERROR
writes a message on stderr and aborts immediately, with another message
@@ -41,13 +43,31 @@
is zero when the error is not being detected by the system. */
#define WARN(Args) \
- error Args
+ do { if (error_hook) error_hook (); error Args; } while (0)
#define ERROR(Args) \
- (error Args, exit_status = PAXEXIT_FAILURE)
+ do \
+ { \
+ if (error_hook) error_hook (); \
+ error Args; \
+ exit_status = PAXEXIT_FAILURE; \
+ } \
+ while (0)
#define FATAL_ERROR(Args) \
- (error Args, fatal_exit ())
+ do \
+ { \
+ if (error_hook) error_hook (); \
+ error Args; \
+ fatal_exit (); \
+ } \
+ while (0)
#define USAGE_ERROR(Args) \
- (error Args, usage (PAXEXIT_FAILURE))
+ do \
+ { \
+ if (error_hook) error_hook (); \
+ error Args; \
+ usage (PAXEXIT_FAILURE); \
+ } \
+ while (0)
extern int exit_status;