]> git.scottworley.com Git - tl-append/blame - common.c
License: GPL 3
[tl-append] / common.c
CommitLineData
ef591a4f
SW
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
bab98a3a
SW
18#define _POSIX_C_SOURCE 2
19#include "common.h"
20
d522116b
SW
21#include <stdio.h>
22#include <stdlib.h>
23
0c5417d5 24const char *const FILENAME = "tl.log";
d522116b
SW
25
26void die(const char *message) {
27 fputs(message, stderr);
28 fputc('\n', stderr);
29 exit(1);
30}
31
32void die_err(const char *message) {
33 perror(message);
34 exit(1);
35}
bab98a3a 36
9b76e9d2 37char *encode_time(time_t t) {
bab98a3a
SW
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}