openalbridge/errlib.c
author unc0rr
Fri, 16 Oct 2009 13:22:32 +0000
changeset 2483 a725063e8e05
parent 2444 ace11b7d8eab
child 2529 51e5df1c8462
permissions -rw-r--r--
Update translation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     1
/*
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     2
 
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     3
 module: errlib.c
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     4
 
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     5
 purpose: library of error functions
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     6
 
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     7
 reference: Stevens, Unix network programming (2ed), p.922
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     8
 
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
     9
 */
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    10
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    11
#include "errlib.h"
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    12
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    13
#define MAXLINE 4095
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    14
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    15
int daemon_proc = 0; /* set to 0 if stdout/stderr available, else set to 1 */
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    16
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    17
static void err_doit (int errnoflag, int level, const char *fmt, va_list ap)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    18
{
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    19
        int errno_save = errno, n;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    20
        char buf[MAXLINE+1];
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    21
        
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    22
        vsnprintf (buf, MAXLINE, fmt, ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    23
        n = strlen(buf);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    24
        if (errnoflag)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    25
                snprintf (buf+n, MAXLINE-n, ": %s", strerror(errno_save));
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    26
        strcat (buf, "\n");
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    27
        
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    28
        if (daemon_proc)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    29
                syslog (level, buf);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    30
        else {
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    31
                fflush (stdout);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    32
                fprintf (stderr, buf);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    33
                fflush (stderr);
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    34
        }
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    35
        
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    36
        return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    37
}
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    38
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    39
void err_ret (const char *fmt, ...)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    40
{
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    41
        va_list ap;
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    42
        
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    43
        va_start (ap, fmt);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    44
        err_doit (1, LOG_INFO, fmt, ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    45
        va_end (ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    46
        return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    47
}
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    48
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    49
void err_sys (const char *fmt, ...)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    50
{
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    51
        va_list ap;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    52
        
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    53
        va_start (ap, fmt);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    54
        err_doit (1, LOG_ERR, fmt, ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    55
        va_end (ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    56
        exit (1);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    57
}
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    58
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    59
void err_msg (const char *fmt, ...)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    60
{
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    61
        va_list ap;
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    62
        
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    63
        va_start (ap, fmt);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    64
        err_doit (0, LOG_INFO, fmt, ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    65
        va_end (ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    66
        return;
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    67
}
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    68
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    69
void err_quit (const char *fmt, ...)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    70
{
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    71
        va_list ap;
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    72
        
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    73
        va_start (ap, fmt);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    74
        err_doit (0, LOG_ERR, fmt, ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    75
        va_end (ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    76
        exit (1);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    77
}
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    78
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    79
void err_dump (const char *fmt, ...)
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    80
{
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    81
        va_list ap;
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    82
        
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    83
        va_start (ap, fmt);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    84
        err_doit (1, LOG_ERR, fmt, ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    85
        va_end (ap);
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    86
        abort();
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    87
}
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    88