]> git.scottworley.com Git - tl-append/blob - common.c
Release 1.0.1
[tl-append] / common.c
1 /*
2 * tl-append: time-logger appending shell
3 * Copyright (C) 2023 Scott Worley <scottworley@scottworley.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 #define _POSIX_C_SOURCE 2
19 #include "common.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 const char *const FILENAME = "tl.log";
25
26 void die(const char *message) {
27 fputs(message, stderr);
28 fputc('\n', stderr);
29 exit(1);
30 }
31
32 void die_err(const char *message) {
33 perror(message);
34 exit(1);
35 }
36
37 char *encode_time(time_t t) {
38 struct tm tm;
39 localtime_r(&t, &tm);
40 const size_t size = 20;
41 char *out = (char *)malloc(size);
42 if (strftime(out, size, "%Y %m %d %H %M %S", &tm) != size - 1)
43 die("Couldn't format time");
44 return out;
45 }