-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.c
68 lines (60 loc) · 949 Bytes
/
wrapper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/errno.h>
#include <time.h>
#include "wrapper.h"
_Noreturn void exit_fatal_err(int code)
{
Endwin();
perror("fatal");
exit(code);
}
int Clock_gettime(clockid_t clk_id, struct timespec *tp)
{
int ret = clock_gettime(clk_id, tp);
if (ret == -1) {
exit_fatal_err(EXIT_FAILURE);
}
return ret;
}
int Puts(const char *str)
{
int ret = puts(str);
if (ret == EOF) {
exit_fatal_err(EXIT_FAILURE);
}
return ret;
}
int Endwin(void)
{
int ret = endwin();
if (ret == ERR) {
exit(EXIT_FAILURE);
}
return ret;
}
WINDOW *Initscr(void)
{
WINDOW *ret = initscr();
if (ret == NULL) {
exit_fatal_err(EXIT_FAILURE);
}
return ret;
}
int Clear(void)
{
int ret = clear();
if (ret == ERR) {
exit_fatal_err(EXIT_FAILURE);
}
return ret;
}
int Usleep(useconds_t usec)
{
int ret = usleep(usec);
if (ret == -1) {
exit_fatal_err(EXIT_FAILURE);
}
return ret;
}