openalbridge/errlib.c
author nemo
Fri, 26 Mar 2010 00:39:00 +0000
changeset 3068 04ea12322a08
parent 2529 51e5df1c8462
permissions -rw-r--r--
remove utility flag
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
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    13
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    14
#define MAXLINE 4095
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    15
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    16
#ifdef __CPLUSPLUS
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    17
extern "C" {
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    18
#endif 
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    19
        
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    20
        int daemon_proc = 0; /* set to 0 if stdout/stderr available, else set to 1 */
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    21
        
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    22
        static void err_doit (int errnoflag, int level, const char *fmt, va_list ap)
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    23
        {
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    24
                int errno_save = errno, n;
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    25
                char buf[MAXLINE+1];
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    26
                
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    27
                vsnprintf (buf, MAXLINE, fmt, ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    28
                n = strlen(buf);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    29
                if (errnoflag)
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    30
                        snprintf (buf+n, MAXLINE-n, ": %s", strerror(errno_save));
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    31
                strcat (buf, "\n");
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    32
                
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    33
                if (daemon_proc)
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    34
                        syslog (level, buf);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    35
                else {
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    36
                        fflush (stdout);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    37
                        fprintf (stderr, buf);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    38
                        fflush (stderr);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    39
                }
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    40
                
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    41
                return;
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    42
        }
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    43
        
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    44
        void err_ret (const char *fmt, ...)
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    45
        {
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    46
                va_list ap;
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    47
                
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    48
                va_start (ap, fmt);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    49
                err_doit (1, LOG_INFO, fmt, ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    50
                va_end (ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    51
                return;
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    52
        }
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    53
        
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    54
        void err_sys (const char *fmt, ...)
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    55
        {
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    56
                va_list ap;
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    57
                
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    58
                va_start (ap, fmt);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    59
                err_doit (1, LOG_ERR, fmt, ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    60
                va_end (ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    61
                exit (1);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    62
        }
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    63
        
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    64
        void err_msg (const char *fmt, ...)
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    65
        {
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    66
                va_list ap;
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    67
                
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    68
                va_start (ap, fmt);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    69
                err_doit (0, LOG_INFO, fmt, ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    70
                va_end (ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    71
                return;
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    72
        }
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    73
        
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    74
        void err_quit (const char *fmt, ...)
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    75
        {
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    76
                va_list ap;
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    77
                
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    78
                va_start (ap, fmt);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    79
                err_doit (0, LOG_ERR, fmt, ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    80
                va_end (ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    81
                exit (1);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    82
        }
2418
538a777f90c4 fix build and partially moves messages to errlib
koda
parents:
diff changeset
    83
        
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    84
        void err_dump (const char *fmt, ...)
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    85
        {
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    86
                va_list ap;
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    87
                
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    88
                va_start (ap, fmt);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    89
                err_doit (1, LOG_ERR, fmt, ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    90
                va_end (ap);
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    91
                abort();
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    92
        }
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    93
        
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    94
#ifdef __CPLUSPLUS
2444
ace11b7d8eab code cleanup and restore the mute call
koda
parents: 2443
diff changeset
    95
}
2529
51e5df1c8462 restore openalbridge to r2489
koda
parents: 2444
diff changeset
    96
#endif