Annotation of objc/objc-errors.m, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * "Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.0 (the 'License').  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License."
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: /*
        !            25:  *     objc-errors.m
        !            26:  *     Copyright 1988, NeXT, Inc.
        !            27:  */
        !            28: 
        !            29: /*
        !            30:        NXLogObjcError was snarfed from "logErrorInc.c" in the kit.
        !            31:   
        !            32:        Contains code for writing error messages to stderr or syslog.
        !            33:   
        !            34:        This code is included in errors.m in the kit, and in pbs.c
        !            35:        so pbs can use it also.
        !            36: */
        !            37: 
        !            38: #ifdef SHLIB
        !            39: #import "shlib.h"
        !            40: #endif SHLIB
        !            41: 
        !            42: #include <stdarg.h>
        !            43: #import <syslog.h>
        !            44: 
        !            45: #import "objc-private.h"
        !            46: 
        !            47: /*     
        !            48:  *     this routine handles errors that involve an object (or class).
        !            49:  */
        !            50: volatile void __objc_error(id rcv, const char *fmt, ...) 
        !            51: { 
        !            52:        va_list vp; 
        !            53: 
        !            54:        va_start(vp,fmt); 
        !            55:        (*_error)(rcv, fmt, vp); 
        !            56:        va_end(vp);
        !            57:        _objc_error (rcv, fmt, vp);     /* In case (*_error)() returns. */
        !            58: }
        !            59: 
        !            60: #ifndef KERNEL
        !            61: 
        !            62: static int hasTerminal()
        !            63: {
        !            64:     static char hasTerm = -1;
        !            65: 
        !            66:     if (hasTerm == -1) {
        !            67:        int fd = open("/dev/tty", O_RDWR, 0);
        !            68:        if (fd >= 0) {
        !            69:            (void)close(fd);
        !            70:            hasTerm = 1;
        !            71:        } else
        !            72:            hasTerm = 0;
        !            73:     }
        !            74:     return hasTerm;
        !            75: }
        !            76: 
        !            77: void _NXLogError(const char *format, ...)
        !            78: {
        !            79:     va_list ap;
        !            80:     char bigBuffer[4*1024];
        !            81: 
        !            82:     va_start(ap, format);
        !            83:     vsprintf(bigBuffer, format, ap);
        !            84:     va_end(ap);
        !            85:     if (hasTerminal()) {
        !            86:        fwrite(bigBuffer, sizeof(char), strlen(bigBuffer), stderr);
        !            87:        if (bigBuffer[strlen(bigBuffer)-1] != '\n')
        !            88:            fputc('\n', stderr);
        !            89:     } else
        !            90:        syslog(LOG_ERR, "%s", bigBuffer);
        !            91: }
        !            92: 
        !            93: /*
        !            94:  *     this routine is never called directly...it is only called indirectly
        !            95:  *     through "_error", which can be overriden by an application. It is
        !            96:  *     not declared static because it needs to be referenced in 
        !            97:  *     "objc-globaldata.m" (this file organization simplifies the shlib
        !            98:  *     maintenance problem...oh well). It is, however, a "private extern".
        !            99:  */
        !           100: volatile void _objc_error(id self, const char *fmt, va_list ap) 
        !           101: { 
        !           102:     char bigBuffer[4*1024];
        !           103: 
        !           104:     vsprintf (bigBuffer, fmt, ap);
        !           105:     _NXLogError ("objc: %s: %s", object_getClassName (self), bigBuffer);
        !           106: 
        !           107:     abort();           /* generates a core file */
        !           108: }
        !           109: 
        !           110: /*     
        !           111:  *     this routine handles severe runtime errors...like not being able
        !           112:  *     to read the mach headers, allocate space, etc...very uncommon.
        !           113:  */
        !           114: volatile void _objc_fatal(const char *msg)
        !           115: {
        !           116:     _NXLogError("objc: %s\n", msg);
        !           117: 
        !           118:     exit(1);
        !           119: }
        !           120: 
        !           121: /*
        !           122:  *     this routine handles soft runtime errors...like not being able
        !           123:  *      add a category to a class (because it wasn't linked in).
        !           124:  */
        !           125: void _objc_inform(const char *fmt, ...)
        !           126: {
        !           127:     va_list ap; 
        !           128:     char bigBuffer[4*1024];
        !           129: 
        !           130:     va_start (ap,fmt); 
        !           131:     vsprintf (bigBuffer, fmt, ap);
        !           132:     _NXLogError ("objc: %s", bigBuffer);
        !           133:     va_end (ap);
        !           134: }
        !           135: 
        !           136: #else /* not KERNEL */
        !           137: 
        !           138: extern int vlog(int level, const char *format, va_list ap);
        !           139: extern volatile void panic(const char *reason);
        !           140: 
        !           141: /* special panic versions of the objc error routines */
        !           142: 
        !           143: void _NXLogError(const char *format, ...)
        !           144: {
        !           145:         va_list ap;
        !           146:         
        !           147:         va_start(ap, format);
        !           148:         vlog(LOG_ERR, format, ap);
        !           149:         va_end(ap);
        !           150:        if(format[strlen(format)-1] != '\n') {
        !           151:                log(LOG_ERR, "\n");
        !           152:        }
        !           153: }
        !           154: 
        !           155: volatile void _objc_error(id self, const char *fmt, va_list ap) 
        !           156: { 
        !           157:        log(LOG_ERR, "objc error: %s ", object_getClassName(self));
        !           158:        vlog(LOG_ERR, fmt, ap);
        !           159:        if(fmt[strlen(fmt)-1] != '\n') {
        !           160:                log(LOG_ERR, "\n");
        !           161:        }
        !           162:        abort();
        !           163: }
        !           164: 
        !           165: volatile void _objc_fatal(const char *msg)
        !           166: {
        !           167:        printf("objc fatal: %s\n", msg);
        !           168:        panic("Objective-C fatal");
        !           169: }
        !           170: 
        !           171: void _objc_inform(const char *fmt, ...)
        !           172: {
        !           173:         va_list ap;
        !           174: 
        !           175:         va_start(ap, fmt);
        !           176:        vlog(LOG_ERR, fmt, ap);
        !           177:        va_end(ap);
        !           178:        if(fmt[strlen(fmt)-1] != '\n') {
        !           179:                log(LOG_ERR, "\n");
        !           180:        }
        !           181: }
        !           182: 
        !           183: #endif /* not KERNEL */

unix.superglobalmegacorp.com

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