From 8e3df79803e42e12148bfc6d5df675859ba3e122 Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Fri, 24 Mar 2023 17:05:07 +0100 Subject: Move util.h and util.c in common --- common/util.c | 29 +++++++++++++++++++++++++++++ common/util.h | 22 ++++++++++++++++++++++ seitan-cooker/Makefile | 7 ++++--- seitan-cooker/util.c | 29 ----------------------------- seitan-cooker/util.h | 22 ---------------------- 5 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 common/util.c create mode 100644 common/util.h delete mode 100644 seitan-cooker/util.c delete mode 100644 seitan-cooker/util.h diff --git a/common/util.c b/common/util.c new file mode 100644 index 0000000..a2ecce0 --- /dev/null +++ b/common/util.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +/* seitan - Syscall Expressive Interpreter, Transformer and Notifier + * + * cooker/util.c - Convenience routines + * + * Copyright 2023 Red Hat GmbH + * Author: Stefano Brivio + */ + +#include +#include +#include + +#define logfn(name) \ +void name(const char *format, ...) { \ + va_list args; \ + \ + va_start(args, format); \ + (void)vfprintf(stderr, format, args); \ + va_end(args); \ + if (format[strlen(format)] != '\n') \ + fprintf(stderr, "\n"); \ +} + +logfn(err) +logfn(info) +logfn(debug) + diff --git a/common/util.h b/common/util.h new file mode 100644 index 0000000..84dc3db --- /dev/null +++ b/common/util.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + * Copyright 2023 Red Hat GmbH + * Author: Stefano Brivio + */ + +#ifndef UTIL_H +#define UTIL_H + +#define BIT(n) (1UL << (n)) + +void err(const char *format, ...); +void info(const char *format, ...); +void debug(const char *format, ...); + +#define die(...) \ + do { \ + fprintf(stderr, "%s:%i: ", __FILE__, __LINE__); \ + err(__VA_ARGS__); \ + exit(EXIT_FAILURE); \ + } while (0) + +#endif /* UTIL_H */ diff --git a/seitan-cooker/Makefile b/seitan-cooker/Makefile index 8741879..241ad4b 100644 --- a/seitan-cooker/Makefile +++ b/seitan-cooker/Makefile @@ -7,12 +7,13 @@ # Copyright 2023 Red Hat GmbH # Author: Stefano Brivio -SRCS := calls.c emit.c gluten.c main.c parse.c parson.c util.c calls/net.c -HEADERS := calls.h cooker.h emit.h gluten.h parse.h parson.h util.h calls/net.h +COMMON_DIR := ../common +SRCS := calls.c emit.c gluten.c main.c parse.c parson.c $(COMMON_DIR)/util.c calls/net.c +HEADERS := calls.h cooker.h emit.h gluten.h parse.h parson.h calls/net.h $(COMMON_DIR)/util.h BIN := $(OUTDIR)cooker cooker: $(SRCS) $(HEADERS) - $(CC) -O0 -g -Wall -Wextra -pedantic -std=c99 -o $(BIN) $(SRCS) + $(CC) -O0 -g -Wall -Wextra -pedantic -std=c99 -I$(COMMON_DIR) -o $(BIN) $(SRCS) all: cooker diff --git a/seitan-cooker/util.c b/seitan-cooker/util.c deleted file mode 100644 index a2ecce0..0000000 --- a/seitan-cooker/util.c +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later - -/* seitan - Syscall Expressive Interpreter, Transformer and Notifier - * - * cooker/util.c - Convenience routines - * - * Copyright 2023 Red Hat GmbH - * Author: Stefano Brivio - */ - -#include -#include -#include - -#define logfn(name) \ -void name(const char *format, ...) { \ - va_list args; \ - \ - va_start(args, format); \ - (void)vfprintf(stderr, format, args); \ - va_end(args); \ - if (format[strlen(format)] != '\n') \ - fprintf(stderr, "\n"); \ -} - -logfn(err) -logfn(info) -logfn(debug) - diff --git a/seitan-cooker/util.h b/seitan-cooker/util.h deleted file mode 100644 index 84dc3db..0000000 --- a/seitan-cooker/util.h +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later - * Copyright 2023 Red Hat GmbH - * Author: Stefano Brivio - */ - -#ifndef UTIL_H -#define UTIL_H - -#define BIT(n) (1UL << (n)) - -void err(const char *format, ...); -void info(const char *format, ...); -void debug(const char *format, ...); - -#define die(...) \ - do { \ - fprintf(stderr, "%s:%i: ", __FILE__, __LINE__); \ - err(__VA_ARGS__); \ - exit(EXIT_FAILURE); \ - } while (0) - -#endif /* UTIL_H */ -- cgit v1.2.3