blob: f6ec0033a9c31187e8e24e7ce9d09fb6ec60b39c [file] [log] [blame]
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -07001/*
2 * Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7#ifndef UTIL_H
8#define UTIL_H
9
David Sodmanbbcb0522014-09-19 10:34:07 -070010#include <stdio.h>
11#include <stdlib.h>
12#include <stdarg.h>
David Sodman8ef20062015-01-06 09:23:40 -080013#include <stdint.h>
David Sodmane46ea8a2015-03-13 15:47:12 -070014#include <stdbool.h>
David Sodmanbbcb0522014-09-19 10:34:07 -070015#include <time.h>
16
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070017#define MAX(A, B) ((A) > (B) ? (A) : (B))
David Sodman8ef20062015-01-06 09:23:40 -080018#define MIN(A, B) ((A) < (B) ? (A) : (B))
19
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070020#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*(A)))
21
David Sodmanbbcb0522014-09-19 10:34:07 -070022#define MS_PER_SEC (1000LL)
23#define NS_PER_SEC (1000LL * 1000LL * 1000LL)
24#define NS_PER_MS (NS_PER_SEC / MS_PER_SEC);
25
26/* Returns the current CLOCK_MONOTONIC time in milliseconds. */
27inline int64_t get_monotonic_time_ms() {
28 struct timespec spec;
29 clock_gettime(CLOCK_MONOTONIC, &spec);
30 return MS_PER_SEC * spec.tv_sec + spec.tv_nsec / NS_PER_MS;
31}
32
33void LOG(int severity, const char* fmt, ...);
34void daemonize();
Stéphane Marchesin00ff1872015-12-14 13:40:09 -080035void parse_location(char* loc_str, int* x, int* y);
36void parse_filespec(char* filespec, char* filename,
37 int32_t* offset_x, int32_t* offset_y, uint32_t* duration,
David Sodman8ef20062015-01-06 09:23:40 -080038 uint32_t default_duration, int32_t default_x, int32_t default_y);
39void parse_image_option(char* optionstr, char** name, char** val);
David Sodmanbbcb0522014-09-19 10:34:07 -070040
Dominik Behr2b9f1232016-08-02 01:11:12 -070041/* make sure stdio file descriptors are somewhat sane */
42void fix_stdio(void);
David Sodmanbbcb0522014-09-19 10:34:07 -070043
44#define ERROR (1)
45#define WARNING (2)
46#define INFO (4)
47
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070048#endif