Select Git revision
config.py.example
-
Martin Mareš authoredMartin Mareš authored
util.c 875 B
/*
* On-screen Display Daemon -- Utility Functions
*
* (c) 2010 Martin Mares <mj@ucw.cz>
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/time.h>
#include "osd.h"
#include "util.h"
void __attribute__((noreturn)) __attribute__((format(printf,1,2)))
die(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fputs("osdd: ", stderr);
vfprintf(stderr, fmt, args);
fputc('\n', stderr);
exit(1);
}
void *
xmalloc(int size)
{
void *p = malloc(size);
if (!p)
die("Failed to allocate %d bytes of memory", size);
return p;
}
void *
xrealloc(void *ptr, int size)
{
void *p = realloc(ptr, size);
if (!p)
die("Failed to re-allocate %d bytes of memory", size);
return p;
}
timestamp_t
get_current_time(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (timestamp_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
}