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 $@ $^
.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
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+
+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);
+}
--- /dev/null
+extern const char *FILENAME;
+
+void die(const char *message);
+
+void die_err(const char *message);
#include <string.h>
#include <time.h>
+#include "common.h"
+
typedef struct expectation {
time_t a, 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");
}
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++) {
#include <stdio.h>
#include <stdlib.h>
-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) {