1/*
2 * Copyright © 2016-2018 Sören Tempel
3 *
4 * This program is free software: you can redistribute it and/or
5 * modify it under the terms of the GNU Affero General Public
6 * License as published by the Free Software Foundation, either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef TMSIM_UTIL_H
20#define TMSIM_UTIL_H
21
22#include <pthread.h>
23#include <semaphore.h>
24#include <stdio.h>
25#include <stdlib.h>
26
27#include <sys/types.h>
28
29/**
30 * Macro which calls perror(3) and terminates the program with EXIT_FAILURE.
31 *
32 * @param msg String passed as a first argument to perror(3).
33 */
34#define die(msg) \
35 do { \
36 perror(msg); \
37 exit(EXIT_FAILURE); \
38 } while (0)
39
40int xstrncmp(char *, char *, size_t, size_t *);
41ssize_t readfile(char **, char *);
42char *mark(size_t, char *);
43
44char *linenum(char *, unsigned int);
45size_t endofline(char *);
46
47char *estrndup(char *, size_t);
48void *emalloc(size_t);
49void *erealloc(void *, size_t);
50
51void pthread_mutex_elock(pthread_mutex_t *);
52void pthread_mutex_eunlock(pthread_mutex_t *);
53
54void sem_ewait(sem_t *);
55void sem_epost(sem_t *);
56
57#endif