"Fossies" - the Fresh Open Source Software Archive 
Member "HTTPing-2.9/error.c" (29 Oct 2022, 1013 Bytes) of package /linux/www/HTTPing-2.9.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "error.c" see the
Fossies "Dox" file reference documentation.
1 /* Released under AGPL v3 with exception for the OpenSSL library. See license.txt */
2
3 #include <libintl.h>
4 #include <errno.h>
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #include <signal.h>
11
12 char last_error[4096] = { 0 };
13
14 extern char json_output;
15
16 void error_exit(char *format, ...)
17 {
18 int e = errno;
19 va_list ap;
20
21 va_start(ap, format);
22 (void)vfprintf(stderr, format, ap);
23 va_end(ap);
24
25 if (json_output) {
26 printf("\n]\n");
27 }
28
29 fprintf(stderr, gettext("\n\nerrno=%d which means %s (if applicable)\n"), e, strerror(e));
30
31 exit(1);
32 }
33
34 void set_error(const char *fmt, ...)
35 {
36 int buffer_size = sizeof last_error;
37 va_list ap;
38
39 if (last_error[0])
40 fprintf(stderr, "%s\n", last_error);
41
42 va_start(ap, fmt);
43 if (vsnprintf(last_error, sizeof last_error, fmt, ap) >= buffer_size)
44 error_exit(gettext("Error message '%s' truncated"), last_error);
45 va_end(ap);
46 }
47
48 void clear_error()
49 {
50 last_error[0] = 0x00;
51 }
52
53 char * get_error()
54 {
55 return last_error;
56 }