1 /* 2 * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Copyright 2019, Haiku, Inc. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #undef NDEBUG 9 // just in case 10 11 #include <OS.h> 12 13 #include <assert.h> 14 #include <signal.h> 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <string.h> 18 19 20 extern char* __progname; 21 22 23 void 24 __assert_fail(const char* assertion, const char* file, unsigned int line, 25 const char* function) 26 { 27 fprintf(stderr, "%s: %s:%d:%s: %s\n", __progname, file, line, function, 28 assertion); 29 30 // If there's no handler installed for SIGABRT, call debugger(). 31 struct sigaction signalAction; 32 if (sigaction(SIGABRT, NULL, &signalAction) == 0 33 && signalAction.sa_handler == SIG_DFL) { 34 debugger(assertion); 35 } 36 37 abort(); 38 } 39 40 41 void 42 __assert_perror_fail(int error, const char* file, unsigned int line, 43 const char* function) 44 { 45 __assert_fail(strerror(error), file, line, function); 46 } 47