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
13 #if !defined(__FreeBSD__) && !defined(_GNU_SOURCE)
28 /* Parse the given string (interpreted as seconds) into a
29 * timespec. On error NULL is returned. The caller is responsible
30 * to free the result. The argument may be NULL, in which case NULL
31 * is returned, too. "0" is also parsed as NULL. */
32 struct timespec
*parse_seconds(const char *s
)
38 struct timespec
*t
= calloc(sizeof *t
, 1);
43 t
->tv_sec
= strtol(s
, &n
, 10);
45 if (*n
!= '\0' || t
->tv_sec
<= 0) {
54 static GList
*atexit_functions
;
56 void vlock_invoke_atexit(void)
58 while (atexit_functions
!= NULL
) {
59 (*(void (**)())&atexit_functions
->data
)();
60 atexit_functions
= g_list_delete_link(atexit_functions
,
65 void vlock_atexit(void (*function
)(void))
67 if (atexit_functions
== NULL
)
68 atexit(vlock_invoke_atexit
);
70 atexit_functions
= g_list_prepend(atexit_functions
,
71 *(void **) &function
);