Annotation of coherent/b/STREAMS/conf_79/ehand.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Error-handling for an application.
        !             3:  */
        !             4: 
        !             5: /*
        !             6:  *-IMPORTS:
        !             7:  *     <sys/compat.h>
        !             8:  *             CONST
        !             9:  *             USE_PROTO
        !            10:  *             ARGS ()
        !            11:  *     <setjmp.h>
        !            12:  *             longjmp ()
        !            13:  *     <stdarg.h>
        !            14:  *             va_list
        !            15:  *             va_start ()
        !            16:  *             va_end ()
        !            17:  *     <stdio.h>
        !            18:  *             stderr
        !            19:  *             fprintf ()
        !            20:  *             putc ()
        !            21:  *             vfprintf ()
        !            22:  *     <stdlib.h>
        !            23:  *             EXIT_FAILURE
        !            24:  *             exit ()
        !            25:  */
        !            26: 
        !            27: #include <sys/compat.h>
        !            28: #include <setjmp.h>
        !            29: #include <stdarg.h>
        !            30: #include <stdio.h>
        !            31: #include <stdlib.h>
        !            32: 
        !            33: #include "ehand.h"
        !            34: 
        !            35: 
        !            36: /*
        !            37:  * Some ancient systems do not define EXIT_SUCCESS or EXIT_FAILURE.
        !            38:  */
        !            39: 
        !            40: #ifndef        EXIT_FAILURE
        !            41: #define        EXIT_FAILURE    1
        !            42: #endif
        !            43: 
        !            44: 
        !            45: ehand_t              * estack_base;
        !            46: 
        !            47: 
        !            48: /*
        !            49:  * Throw an error - write out an error report and throw to the last installed
        !            50:  * handler (or call exit () if there is no installed handler).
        !            51:  */
        !            52: 
        !            53: 
        !            54: #ifdef USE_PROTO
        !            55: void (throw_error) (CONST char * fmt, ...)
        !            56: #else
        !            57: void
        !            58: throw_error ARGS ((fmt))
        !            59: CONST char    *        fmt;
        !            60: #endif
        !            61: {
        !            62: #if    0
        !            63:        /*
        !            64:         * There is no vfprintf () under any version of Coherent up to 4.0.1,
        !            65:         * so we must simulate the effect using the obsolete extension that
        !            66:         * Coherent *does* support, namely the %r (recursive) format.
        !            67:         */
        !            68:        (void) fprintf (stderr, "ERROR : %r", & fmt);
        !            69: #else
        !            70:        va_list         args;
        !            71: 
        !            72:        va_start (args, fmt);
        !            73:        (void) fprintf (stderr, "ERROR : ");
        !            74:        (void) vfprintf (stderr, fmt, args);
        !            75:        va_end (args);
        !            76: #endif
        !            77: 
        !            78:        putc ('\n', stderr);
        !            79: 
        !            80:        if (estack_base == NULL)
        !            81:                exit (EXIT_FAILURE);
        !            82: 
        !            83:        longjmp (estack_base->eh_buf, -1);
        !            84: }
        !            85: 
        !            86: 
        !            87: /*
        !            88:  * This function can be called when the code to pop the current exception
        !            89:  * handler detects that the stack base is not where it should be (implying
        !            90:  * that an inner function did not pop its handler).
        !            91:  */
        !            92: 
        !            93: #ifdef USE_PROTO
        !            94: void (error_error) (CONST char * file, int line)
        !            95: #else
        !            96: void
        !            97: error_error ARGS ((file, line))
        !            98: CONST char    *        file;
        !            99: int            line;
        !           100: #endif
        !           101: {
        !           102:        fprintf (stderr, "FATAL ERROR : Exception handler nesting error ");
        !           103:        fprintf (stderr, "detected in file\n  '%s' at line %d\n", file, line);
        !           104: 
        !           105:        exit (EXIT_FAILURE);
        !           106: }
        !           107: 
        !           108: 
        !           109: /*
        !           110:  * Chain to the next error-handler in the stack of error handlers after the
        !           111:  * handler passed to us.
        !           112:  */
        !           113: 
        !           114: #ifdef USE_PROTO
        !           115: void (chain_error) (ehand_t * err)
        !           116: #else
        !           117: void
        !           118: chain_error ARGS ((err))
        !           119: ehand_t              * err;
        !           120: #endif
        !           121: {
        !           122:        if (err != estack_base)
        !           123:                error_error ("chain_error, " __FILE__, __LINE__);
        !           124: 
        !           125:        if ((estack_base = err->eh_next) == NULL)
        !           126:                exit (EXIT_FAILURE);
        !           127: 
        !           128:        longjmp (estack_base->eh_buf, -1);
        !           129: }
        !           130: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.