]> mj.ucw.cz Git - osdd.git/blob - util.c
Merge branch 'master' of ssh://git.ucw.cz/home/mj/GIT/osdd
[osdd.git] / util.c
1 /*
2  *      On-screen Display Daemon -- Utility Functions
3  *
4  *      (c) 2010 Martin Mares <mj@ucw.cz>
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <stdarg.h>
10 #include <sys/time.h>
11
12 #include "osd.h"
13
14 void __attribute__((noreturn)) __attribute__((format(printf,1,2)))
15 die(char *fmt, ...)
16 {
17   va_list args;
18   va_start(args, fmt);
19   fputs("osdd: ", stderr);
20   vfprintf(stderr, fmt, args);
21   fputc('\n', stderr);
22   exit(1);
23 }
24
25 void *
26 xmalloc(int size)
27 {
28   void *p = malloc(size);
29   if (!p)
30     die("Failed to allocate %d bytes of memory", size);
31   return p;
32 }
33
34 timestamp_t
35 get_current_time(void)
36 {
37   struct timeval tv;
38   gettimeofday(&tv, NULL);
39   return (timestamp_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
40 }