#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) {
}
static void write_line(const char *line) {
+ const char *now = encode_time(time(NULL));
FILE *f = fopen(FILENAME, "a");
if (f == NULL)
die_err("Error opening output file");
+ if (fputs(now, f) == EOF)
+ die("Error writing to output file");
+ if (fputc(' ', f) == EOF)
+ die("Error writing to output file");
if (fputs(line, f) == EOF)
die("Error writing to output file");
if (fclose(f) != 0)