• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2008 The Android Open Source Project
2 **
3 ** This software is licensed under the terms of the GNU General Public
4 ** License version 2, as published by the Free Software Foundation, and
5 ** may be copied, distributed, and modified under those terms.
6 **
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 ** GNU General Public License for more details.
11 */
12 #include "android/utils/panic.h"
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 static void __attribute__((noreturn))
_android_panic_defaultHandler(const char * fmt,va_list args)17 _android_panic_defaultHandler( const char*  fmt, va_list  args )
18 {
19     fprintf(stderr, "PANIC: ");
20     vfprintf(stderr, fmt, args);
21     exit(1);
22 }
23 
24 static APanicHandlerFunc  _panicHandler = _android_panic_defaultHandler;
25 
android_panic(const char * fmt,...)26 void android_panic( const char*  fmt, ... )
27 {
28     va_list  args;
29     va_start(args, fmt);
30     android_vpanic(fmt, args);
31     va_end(args);
32 }
33 
34 /* Variant of android_vpanic which take va_list formating arguments */
android_vpanic(const char * fmt,va_list args)35 void android_vpanic( const char*  fmt, va_list  args )
36 {
37     _panicHandler(fmt, args);
38 }
39 
android_panic_registerHandler(APanicHandlerFunc handler)40 void android_panic_registerHandler( APanicHandlerFunc  handler )
41 {
42     if (handler == NULL)
43         android_panic("Passing NULL to %s", __FUNCTION__);
44 
45     _panicHandler = handler;
46 }
47