~donmcc/ood

ref: 1182412fd4ece0cb55c4b3ebefee78b22c8c15bd ood/src/libood/ood/halt.c -rw-r--r-- 564 bytes
1182412fDon McCaughey Add `ood_halt()` function. 3 months ago
                                                                                
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
#include "halt.h"

#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


static void
halt(char const *message, int status)
{
    fprintf(stderr, "ERROR: %s\n", message);
    fflush(stderr);
    exit(status);
}


void
ood_halt(char const *message)
{
    if (message && message[0]) {
        halt(message, EXIT_FAILURE);
    } else {
        halt("No message", EXIT_FAILURE);
    }
}


void
ood_halt_on_error(void)
{
    if (errno) {
        halt(strerror(errno), errno);
    } else {
        halt("No error number", EXIT_FAILURE);
    }
}