misc/openalbridge/errlib.c
author koda
Wed, 21 Apr 2010 10:22:06 +0000
changeset 3362 8d3b4d19ce27
parent 3353 a767dd3786b5
permissions -rw-r--r--
in reprocessing openalbridge, a lot of code cleanup and simplification
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     1
/*
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     2
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     3
 module: errlib.c
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     4
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     5
 purpose: library of error functions
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     6
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     7
 reference: Stevens, Unix network programming (2ed), p.922
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
     8
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
     9
 */
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    10
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    11
#include "errlib.h"
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    12
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    13
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    14
#define MAXLINE 4095
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    15
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    16
int daemon_proc = 0; /* set to 0 if stdout/stderr available, else set to 1 */
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    17
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    18
static void err_doit (int errnoflag, int level, const char *fmt, va_list ap) {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    19
    int errno_save = errno, n;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    20
    char buf[MAXLINE+1];
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    21
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    22
    vsnprintf (buf, MAXLINE, fmt, ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    23
    n = strlen(buf);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    24
    if (errnoflag)
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    25
        snprintf (buf+n, MAXLINE-n, ": %s", strerror(errno_save));
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    26
    strcat (buf, "\n");
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    27
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    28
    if (daemon_proc)
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    29
        syslog (level, buf);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    30
    else {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    31
        fflush (stdout);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    32
        fprintf (stderr, "%s", buf);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    33
        fflush (stderr);
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    34
    }
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    35
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    36
    return;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    37
}
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    38
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    39
void err_ret (const char *fmt, ...) {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    40
    va_list ap;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    41
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    42
    va_start (ap, fmt);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    43
    err_doit (1, LOG_INFO, fmt, ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    44
    va_end (ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    45
    return;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    46
}
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    47
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    48
void err_sys (const char *fmt, ...) {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    49
    va_list ap;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    50
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    51
    va_start (ap, fmt);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    52
    err_doit (1, LOG_ERR, fmt, ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    53
    va_end (ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    54
    exit (1);
3353
a767dd3786b5 OpenAL makes a comeback! (might require some cleanup)
koda
parents:
diff changeset
    55
}
3362
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    56
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    57
void err_msg (const char *fmt, ...) {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    58
    va_list ap;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    59
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    60
    va_start (ap, fmt);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    61
    err_doit (0, LOG_INFO, fmt, ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    62
    va_end (ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    63
    return;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    64
}
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    65
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    66
void err_quit (const char *fmt, ...) {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    67
    va_list ap;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    68
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    69
    va_start (ap, fmt);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    70
    err_doit (0, LOG_ERR, fmt, ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    71
    va_end (ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    72
    exit (1);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    73
}
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    74
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    75
void err_dump (const char *fmt, ...) {
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    76
    va_list ap;
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    77
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    78
    va_start (ap, fmt);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    79
    err_doit (1, LOG_ERR, fmt, ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    80
    va_end (ap);
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    81
    abort();
8d3b4d19ce27 in reprocessing openalbridge, a lot of code cleanup and simplification
koda
parents: 3353
diff changeset
    82
}