2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Copyright 1988-2001, NeXT Software, Inc., Apple Computer, Inc.
34 #include <sys/fcntl.h>
36 #import "objc-private.h"
38 static volatile void _objc_trap(void);
41 static int hasTerminal()
43 static char hasTerm = -1;
46 int fd = open("/dev/tty", O_RDWR, 0);
56 void _objc_syslog(const char *format, ...)
59 char bigBuffer[4*1024];
62 vsnprintf(bigBuffer, sizeof(bigBuffer), format, ap);
67 fwrite(bigBuffer, sizeof(char), strlen(bigBuffer), stderr);
68 if (bigBuffer[strlen(bigBuffer)-1] != '\n')
71 syslog(LOG_ERR, "%s", bigBuffer);
75 * this routine handles errors that involve an object (or class).
77 volatile void __objc_error(id rcv, const char *fmt, ...)
82 (*_error)(rcv, fmt, vp);
84 _objc_error (rcv, fmt, vp); /* In case (*_error)() returns. */
88 * this routine is never called directly...it is only called indirectly
89 * through "_error", which can be overriden by an application. It is
90 * not declared static because it needs to be referenced in
91 * "objc-globaldata.m" (this file organization simplifies the shlib
92 * maintenance problem...oh well). It is, however, a "private extern".
94 volatile void _objc_error(id self, const char *fmt, va_list ap)
96 char bigBuffer[4*1024];
98 vsnprintf (bigBuffer, sizeof(bigBuffer), fmt, ap);
99 _objc_syslog ("objc: %s: %s", object_getClassName (self), bigBuffer);
105 * this routine handles severe runtime errors...like not being able
106 * to read the mach headers, allocate space, etc...very uncommon.
108 volatile void _objc_fatal(const char *fmt, ...)
111 char bigBuffer[4*1024];
114 vsnprintf (bigBuffer, sizeof(bigBuffer), fmt, ap);
115 _objc_syslog ("objc: %s", bigBuffer);
122 * this routine handles soft runtime errors...like not being able
123 * add a category to a class (because it wasn't linked in).
125 void _objc_inform(const char *fmt, ...)
128 char bigBuffer[4*1024];
131 vsnprintf (bigBuffer, sizeof(bigBuffer), fmt, ap);
132 _objc_syslog ("objc: %s", bigBuffer);
137 /* Kill the process in a way that generates a crash log.
138 * This is better than calling exit(). */
139 static volatile void _objc_trap(void)
141 #if defined(__ppc__) || defined(ppc)
143 #elif defined(__i386__) || defined(i386)
146 #warning _objc_trap not specified for this architecture; using _exit instead