From 4a099cec3aea9821cf5671838252f22a37782a8f Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sat, 27 Mar 2021 13:38:56 -0500 Subject: [PATCH] Move msg() to bup/io.[hc] in preparation for more sharing We're going to need to share some python compatibility code between dev/python and bup, etc., so create src/bup for the shared code, and move msg() there. Signed-off-by: Rob Browning --- Makefile | 8 ++++---- lib/cmd/bup.c | 14 +------------- src/bup/io.c | 35 +++++++++++++++++++++++++++++++++++ src/bup/io.h | 6 ++++++ 4 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 src/bup/io.c create mode 100644 src/bup/io.h diff --git a/Makefile b/Makefile index b16cec5..028894e 100644 --- a/Makefile +++ b/Makefile @@ -151,7 +151,7 @@ install: all $(INSTALL) -pm 0644 lib/bup/source_info.py $(dest_libdir)/bup/; \ fi -embed_cflags := $(bup_python_cflags_embed) $(bup_shared_cflags) +embed_cflags := $(bup_python_cflags_embed) $(bup_shared_cflags) -I$(CURDIR)/src embed_ldflags := $(bup_python_ldflags_embed) $(bup_shared_ldflags) config/config.h: config/config.vars @@ -174,18 +174,18 @@ dev/python: dev/python-proposed clean_paths += dev/bup-exec generated_dependencies += dev/bup-exec.d dev/bup-exec: CFLAGS += -D BUP_DEV_BUP_EXEC=1 -dev/bup-exec: lib/cmd/bup.c +dev/bup-exec: lib/cmd/bup.c src/bup/io.c $(cc_bin) clean_paths += dev/bup-python generated_dependencies += dev/bup-python.d dev/bup-python: CFLAGS += -D BUP_DEV_BUP_PYTHON=1 -dev/bup-python: lib/cmd/bup.c +dev/bup-python: lib/cmd/bup.c src/bup/io.c $(cc_bin) clean_paths += lib/cmd/bup generated_dependencies += lib/cmd/bup.d -lib/cmd/bup: lib/cmd/bup.c +lib/cmd/bup: lib/cmd/bup.c src/bup/io.c $(cc_bin) clean_paths += lib/bup/_helpers$(soext) diff --git a/lib/cmd/bup.c b/lib/cmd/bup.c index 807e260..636c017 100644 --- a/lib/cmd/bup.c +++ b/lib/cmd/bup.c @@ -21,19 +21,7 @@ #include #include -__attribute__ ((format(printf, 2, 3))) -static void -die(int exit_status, const char * const msg, ...) -{ - if (fputs("bup: ", stderr) == EOF) - exit(3); - va_list ap; - va_start(ap, msg);; - if (vfprintf(stderr, msg, ap) < 0) - exit(3); - va_end(ap); - exit(exit_status); -} +#include "bup/io.h" static int prog_argc = 0; static char **prog_argv = NULL; diff --git a/src/bup/io.c b/src/bup/io.c new file mode 100644 index 0000000..5a0bae1 --- /dev/null +++ b/src/bup/io.c @@ -0,0 +1,35 @@ + +#define _GNU_SOURCE 1 +#undef NDEBUG + +#include +#include + +#include "bup/io.h" + +__attribute__ ((format(printf, 2, 3))) +void +msg(FILE* f, const char * const msg, ...) +{ + if (fputs("bup: ", f) == EOF) + exit(3); + va_list ap; + va_start(ap, msg); + if (vfprintf(f, msg, ap) < 0) + exit(3); + va_end(ap); +} + +__attribute__ ((format(printf, 2, 3))) +void +die(int exit_status, const char * const msg, ...) +{ + if (fputs("bup: ", stderr) == EOF) + exit(3); + va_list ap; + va_start(ap, msg); + if (vfprintf(stderr, msg, ap) < 0) + exit(3); + va_end(ap); + exit(exit_status); +} diff --git a/src/bup/io.h b/src/bup/io.h new file mode 100644 index 0000000..d355e6b --- /dev/null +++ b/src/bup/io.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +void msg(FILE* f, const char * const msg, ...); +void die(int exit_status, const char * const msg, ...); -- 2.39.2