]> git.scottworley.com Git - tl-append/blame - common.c
Hold a lock while appending
[tl-append] / common.c
CommitLineData
bab98a3a
SW
1#define _POSIX_C_SOURCE 2
2#include "common.h"
3
d522116b
SW
4#include <stdio.h>
5#include <stdlib.h>
6
0c5417d5 7const char *const FILENAME = "tl.log";
d522116b
SW
8
9void die(const char *message) {
10 fputs(message, stderr);
11 fputc('\n', stderr);
12 exit(1);
13}
14
15void die_err(const char *message) {
16 perror(message);
17 exit(1);
18}
bab98a3a
SW
19
20const char *encode_time(time_t t) {
21 struct tm tm;
22 localtime_r(&t, &tm);
23 const size_t size = 20;
24 char *out = (char *)malloc(size);
25 if (strftime(out, size, "%Y %m %d %H %M %S", &tm) != size - 1)
26 die("Couldn't format time");
27 return out;
28}