-
Notifications
You must be signed in to change notification settings - Fork 0
/
hope.c
58 lines (51 loc) · 1.04 KB
/
hope.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
/* hope.c -- runtime diagnostics
*
* Copyright Dean Scarff
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char *program_invocation = "";
#ifndef NDEBUG
#define FL , const char *file, unsigned line
#define PFL() fprintf(stderr, "(From %s:%u)\n", file, line)
#else
#define FL
#define PFL()
#endif
#pragma GCC visibility push(hidden)
void
hope_(const char *e FL)
{
fprintf(stderr, "%s: %s\n", program_invocation, e);
PFL();
exit(EXIT_FAILURE);
}
void
hope2_(const char *e, const char *strerr FL)
{
fprintf(stderr, "%s: %s: %s\n", program_invocation, e, strerr);
PFL();
exit(EXIT_FAILURE);
}
void *
xmalloc_(size_t size FL)
{
void *p = malloc(size);
if (!p) {
fprintf(
stderr, "%s: %s\n", program_invocation, strerror(errno));
PFL();
exit(EXIT_FAILURE);
}
return p;
}
#pragma GCC visibility pop