2 libparted - a library for manipulating disk partitions
3 Copyright (C) 2000, 2005, 2007, 2009-2010 Free Software Foundation,
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <parted/parted.h>
22 #include <parted/debug.h>
26 # define _(String) dgettext (PACKAGE, String)
28 # define _(String) (String)
29 #endif /* ENABLE_NLS */
37 static void default_handler ( const int level, const char* file, int line,
38 const char* function, const char* msg );
39 static PedDebugHandler* debug_handler = &default_handler;
43 * Default debug handler.
44 * Will print all information to stderr.
46 static void default_handler ( const int level, const char* file, int line,
47 const char* function, const char* msg )
49 fprintf ( stderr, "[%d] %s:%d (%s): %s\n",
50 level, file, line, function, msg );
54 * Send a debug message.
55 * Do not call this directly -- use PED_DEBUG() instead.
57 * level log level, 0 ~= "print definitely"
59 void ped_debug ( const int level, const char* file, int line,
60 const char* function, const char* msg, ... )
63 char* msg_concat = ped_malloc(8192);
65 va_start ( arg_list, msg );
66 vsnprintf ( msg_concat, 8192, msg, arg_list );
69 debug_handler ( level, file, line, function, msg_concat );
75 * handler debug handler; NULL for default handler
77 void ped_debug_set_handler ( PedDebugHandler* handler )
79 debug_handler = ( handler ? handler : default_handler );
84 * Do not call this directly -- use PED_ASSERT() instead.
86 void ped_assert (const char* cond_text,
87 const char* file, int line, const char* function)
90 /* Print backtrace stack */
92 char **strings, **string;
93 int size = backtrace(stack, 20);
94 strings = backtrace_symbols(stack, size);
97 printf(_("Backtrace has %d calls on stack:\n"), size);
99 for (string = strings; size > 0; size--, string++)
100 printf(" %d: %s\n", size, *string);
106 /* Throw the exception */
107 ped_exception_throw (
110 _("Assertion (%s) at %s:%d in function %s() failed."),
111 cond_text, file, line, function);