aboutsummaryrefslogtreecommitdiffstats
path: root/vweprintf.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-11-06 20:32:42 +0100
committerMattias Andrée <maandree@kth.se>2018-11-06 20:32:42 +0100
commit0335a7cf215f1c5cba9ae8a49b3dbd1b980a20b1 (patch)
treee87a3444037b27f7a2743ea84e7af1d9ef50c1bf /vweprintf.c
parentAdd tests for mem[p]setelem and add man pages for libsimple_default_failure_exit (diff)
downloadlibsimple-0335a7cf215f1c5cba9ae8a49b3dbd1b980a20b1.tar.gz
libsimple-0335a7cf215f1c5cba9ae8a49b3dbd1b980a20b1.tar.bz2
libsimple-0335a7cf215f1c5cba9ae8a49b3dbd1b980a20b1.tar.xz
Add libsimple_eprintf_preprint and libsimple_eprintf_postprint
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--vweprintf.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/vweprintf.c b/vweprintf.c
index 96a82a7..9263d52 100644
--- a/vweprintf.c
+++ b/vweprintf.c
@@ -6,6 +6,11 @@
extern char *argv0;
+int libsimple_default_failure_exit = 1;
+void (*libsimple_eprintf_preprint)(void) = NULL;
+void (*libsimple_eprintf_postprint)(void) = NULL;
+
+
void
libsimple_vweprintf(const char *fmt, va_list ap)
{
@@ -44,6 +49,8 @@ libsimple_vweprintf(const char *fmt, va_list ap)
suffix1 = "\n";
}
+ if (libsimple_eprintf_preprint)
+ libsimple_eprintf_preprint();
if (message) {
/* This is to avoid mangling when multiple processes are writting. */
fprintf(stderr, "%s%s%s%s%s%s", prefix1, prefix2, message, suffix1, suffix2, suffix3);
@@ -52,6 +59,8 @@ libsimple_vweprintf(const char *fmt, va_list ap)
vfprintf(stderr, fmt, ap);
fprintf(stderr, "%s%s%s", suffix1, suffix2, suffix3);
}
+ if (libsimple_eprintf_postprint)
+ libsimple_eprintf_postprint();
errno = saved_errno;
}
@@ -64,6 +73,18 @@ libsimple_vweprintf(const char *fmt, va_list ap)
# pragma GCC diagnostic ignored "-Wformat-zero-length"
#endif
+static void
+preprint(void)
+{
+ test_fprintf(stderr, "pre\n");
+}
+
+static void
+postprint(void)
+{
+ test_fprintf(stderr, "post\n");
+}
+
int
main(void)
{
@@ -92,15 +113,23 @@ main(void)
for (j = 0; j < 3; j++) {
T("%s%s%s\n", "abc", "123", "xyz");
assert_stderr("%s%s\n", prefix, "abc123xyz");
+ libsimple_eprintf_preprint = preprint;
T("%s%s%s\n", "abc", "123", "\n");
- assert_stderr("%s%s\n", prefix, "abc123\n");
+ assert_stderr("pre\n%s%s\n", prefix, "abc123\n");
+ libsimple_eprintf_preprint = NULL;
+ libsimple_eprintf_postprint = postprint;
T("%s%s%s", "abc", "123", "xyz");
- assert_stderr("%s%s\n", prefix, "abc123xyz");
+ assert_stderr("%s%s\npost\n", prefix, "abc123xyz");
+ libsimple_eprintf_postprint = NULL;
T("%s%s%s", "abc", "123", "\n");
assert_stderr("%s%s\n", prefix, "abc123\n");
errno = EDOM;
+ libsimple_eprintf_preprint = preprint;
+ libsimple_eprintf_postprint = postprint;
T("%s%s%s:", "abc", "123", "\n");
- assert_stderr("%s%s: %s\n", prefix, "abc123\n", strerror(EDOM));
+ assert_stderr("pre\n%s%s: %s\npost\n", prefix, "abc123\n", strerror(EDOM));
+ libsimple_eprintf_preprint = NULL;
+ libsimple_eprintf_postprint = NULL;
errno = ERANGE;
T("%s%s%s:", "abc", "123", "\n");
assert_stderr("%s%s: %s\n", prefix, "abc123\n", strerror(ERANGE));