]> arthur.barton.de Git - bup.git/commitdiff
Move msg() to bup/io.[hc] in preparation for more sharing
authorRob Browning <rlb@defaultvalue.org>
Sat, 27 Mar 2021 18:38:56 +0000 (13:38 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 28 Mar 2021 21:25:18 +0000 (16:25 -0500)
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 <rlb@defaultvalue.org>
Makefile
lib/cmd/bup.c
src/bup/io.c [new file with mode: 0644]
src/bup/io.h [new file with mode: 0644]

index b16cec5702ade4bee92f47e52e7888f53b1824c3..028894eba686884f3af973199ef0fcce4b9208cd 100644 (file)
--- 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)
index 807e26009b028d9bb15f03f140a9be447f37a99e..636c017967eedd231be7b67282bf715fa392f48d 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 
-__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 (file)
index 0000000..5a0bae1
--- /dev/null
@@ -0,0 +1,35 @@
+
+#define _GNU_SOURCE  1
+#undef NDEBUG
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#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 (file)
index 0000000..d355e6b
--- /dev/null
@@ -0,0 +1,6 @@
+#pragma once
+
+#include <stdio.h>
+
+void msg(FILE* f, const char * const msg, ...);
+void die(int exit_status, const char * const msg, ...);