-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
error.cpp
42 lines (34 loc) · 779 Bytes
/
error.cpp
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
// (C) 2018-2023 by Folkert van Heusden
// Released under MIT license
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
#include <Arduino.h>
#elif defined(_WIN32)
#else
#include <ncursesw/ncurses.h>
#endif
#include "error.h"
[[ noreturn ]] void error_exit(bool sys_err, const char *format, ...)
{
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
printf("Fatal error: %s\n", format);
#else
int e = errno;
#if !defined(_WIN32)
(void)endwin();
#endif
va_list ap;
va_start(ap, format);
(void)vfprintf(stderr, format, ap);
va_end(ap);
if (sys_err == true)
fprintf(stderr, "error: %s (%d)\n", strerror(e), e);
exit(1);
#endif
}