src/util.{c, h}: remove obsolete fatal_error functions
[vlock.git] / src / util.c
blob0d7483a1cebe99ac2c6b802b1ba11fcf74e78fe1
1 /* util.c -- utility routines for vlock, the VT locking program for linux
3 * This program is copyright (C) 2007 Frank Benkstein, and is free
4 * software which is freely distributable under the terms of the
5 * GNU General Public License version 2, included as the file COPYING in this
6 * distribution. It is NOT public domain software, and any
7 * redistribution not permitted by the GNU General Public License is
8 * expressly forbidden without prior written permission from
9 * the author.
13 #if !defined(__FreeBSD__) && !defined(_GNU_SOURCE)
14 #define _GNU_SOURCE
15 #endif
17 #include <stdlib.h>
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <errno.h>
22 #include <time.h>
24 #include "util.h"
26 /* Parse the given string (interpreted as seconds) into a
27 * timespec. On error NULL is returned. The caller is responsible
28 * to free the result. The argument may be NULL, in which case NULL
29 * is returned, too. "0" is also parsed as NULL. */
30 struct timespec *parse_seconds(const char *s)
32 if (s == NULL) {
33 return NULL;
34 } else {
35 char *n;
36 struct timespec *t = calloc(sizeof *t, 1);
38 if (t == NULL)
39 return NULL;
41 t->tv_sec = strtol(s, &n, 10);
43 if (*n != '\0' || t->tv_sec <= 0) {
44 free(t);
45 t = NULL;
48 return t;