]> git.ipfire.org Git - thirdparty/gcc.git/blame - libobjc/error.c
Update Copyright years for files modified in 2010.
[thirdparty/gcc.git] / libobjc / error.c
CommitLineData
7b869986
NP
1/* GNU Objective C Runtime Error Functions
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002, 2009, 2010
3 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by the
9Free Software Foundation; either version 3, or (at your option) any
10later version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT
13ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
25
26#include "objc-private/common.h"
27#include "objc-private/error.h"
28
29/* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for
30 malloc, free, etc. on some platforms. It is unclear if we still
575584a9 31 need it, but it can't hurt. */
7b869986
NP
32#define __USE_FIXED_PROTOTYPES__
33#include <stdlib.h>
34#include <stdio.h>
35#include <stdarg.h>
36
37/* Prints an error message and aborts the program. */
38void
39_objc_abort (const char *fmt, ...)
40{
41 va_list ap;
42
43 va_start (ap, fmt);
44 vfprintf (stderr, fmt, ap);
45 abort ();
46 va_end (ap);
47}
48
49/* The rest of the file is deprecated. */
718a8e53 50#include "objc/objc-api.h" /* For objc_error_handler. */
7b869986
NP
51
52/*
53** Error handler function
54** NULL so that default is to just print to stderr
55*/
56static objc_error_handler _objc_error_handler = NULL;
57
58/* Trigger an objc error */
59void
60objc_error (id object, int code, const char *fmt, ...)
61{
62 va_list ap;
63
64 va_start (ap, fmt);
65 objc_verror (object, code, fmt, ap);
66 va_end (ap);
67}
68
69/* Trigger an objc error */
70void
71objc_verror (id object, int code, const char *fmt, va_list ap)
72{
73 BOOL result = NO;
74
75 /* Call the error handler if its there
76 Otherwise print to stderr */
77 if (_objc_error_handler)
78 result = (*_objc_error_handler) (object, code, fmt, ap);
79 else
80 vfprintf (stderr, fmt, ap);
81
82 /* Continue if the error handler says its ok
83 Otherwise abort the program */
84 if (result)
85 return;
86 else
87 abort ();
88}
89
90/* Set the error handler */
91objc_error_handler
92objc_set_error_handler (objc_error_handler func)
93{
94 objc_error_handler temp = _objc_error_handler;
95 _objc_error_handler = func;
96 return temp;
97}