From: Scott Worley Date: Thu, 31 Aug 2023 19:11:01 +0000 (-0700) Subject: A space for test & implementation to share code X-Git-Tag: v1.0.0~17 X-Git-Url: http://git.scottworley.com/tl-append/commitdiff_plain/d522116b5fdc09e3f83fe4f88515dec52a3e0462 A space for test & implementation to share code --- diff --git a/.gitignore b/.gitignore index dad8cbc..60cafa8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +*.o tl-append tl.log diff --git a/Makefile b/Makefile index f5e1548..f4db060 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,11 @@ prefix = /usr/local bindir = $(prefix)/bin INSTALL = install -tl-append: +tl-append: common.o +tl-append-test: common.o +%.o: %.c + $(CC) -Wall -Wextra -pedantic -std=c99 -o $@ -c $^ %: %.c $(CC) -Wall -Wextra -pedantic -std=c99 -o $@ $^ @@ -18,4 +21,7 @@ install: tl-append .PHONY: clean clean: - -rm tl-append tl-append-test tl.log + -rm tl-append tl-append-test tl.log *.o + +tl-append.o: common.h +tl-append-test.o: common.h diff --git a/common.c b/common.c new file mode 100644 index 0000000..ffa4b5a --- /dev/null +++ b/common.c @@ -0,0 +1,15 @@ +#include +#include + +const char *FILENAME = "tl.log"; + +void die(const char *message) { + fputs(message, stderr); + fputc('\n', stderr); + exit(1); +} + +void die_err(const char *message) { + perror(message); + exit(1); +} diff --git a/common.h b/common.h new file mode 100644 index 0000000..e442b2c --- /dev/null +++ b/common.h @@ -0,0 +1,5 @@ +extern const char *FILENAME; + +void die(const char *message); + +void die_err(const char *message); diff --git a/tl-append-test.c b/tl-append-test.c index ea42dc9..6d037cb 100644 --- a/tl-append-test.c +++ b/tl-append-test.c @@ -5,6 +5,8 @@ #include #include +#include "common.h" + typedef struct expectation { time_t a, b; const char *message; @@ -22,19 +24,8 @@ static ex_t expectation(time_t a, time_t b, const char *message) { return exp; } -static void die(const char *message) { - fputs(message, stderr); - fputc('\n', stderr); - exit(1); -} - -static void die_err(const char *message) { - perror(message); - exit(1); -} - static void remove_logfile() { - if (remove("tl.log") != 0) { + if (remove(FILENAME) != 0) { if (errno != ENOENT) { die_err("Error removing log file"); } @@ -59,7 +50,7 @@ static ex_t write_to_tl_append(const char *content) { static void verify_log_contents(ex_t exps[]) { - FILE *f = fopen("tl.log", "r"); + FILE *f = fopen(FILENAME, "r"); if (f == NULL) die_err("Error opening log file"); for (size_t i = 0; !is_end(exps[i]); i++) { diff --git a/tl-append.c b/tl-append.c index 21e23a6..c2f476f 100644 --- a/tl-append.c +++ b/tl-append.c @@ -1,19 +1,9 @@ #include #include -const char *FILENAME = "tl.log"; -const size_t BUF_SIZE = 1024; - -static void die(const char *message) { - fputs(message, stderr); - fputc('\n', stderr); - exit(1); -} +#include "common.h" -static void die_err(const char *message) { - perror(message); - exit(1); -} +const size_t BUF_SIZE = 1024; static void read_line(char *buf) { if (fgets(buf, BUF_SIZE, stdin) == NULL) {