2 libparted - a library for manipulating disk partitions
3 Copyright (C) 2000, 2005, 2007, 2009-2012 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <parted/parted.h>
21 #include <parted/debug.h>
25 # define _(String) dgettext (PACKAGE, String)
27 # define _(String) (String)
28 #endif /* ENABLE_NLS */
36 static void default_handler ( const int level, const char* file, int line,
37 const char* function, const char* msg );
38 static PedDebugHandler* debug_handler = &default_handler;
42 * Default debug handler.
43 * Will print all information to stderr.
45 static void default_handler ( const int level, const char* file, int line,
46 const char* function, const char* msg )
48 fprintf ( stderr, "[%d] %s:%d (%s): %s\n",
49 level, file, line, function, msg );
53 * Send a debug message.
54 * Do not call this directly -- use PED_DEBUG() instead.
56 * level log level, 0 ~= "print definitely"
58 void ped_debug ( const int level, const char* file, int line,
59 const char* function, const char* msg, ... )
62 char* msg_concat = ped_malloc(8192);
64 va_start ( arg_list, msg );
65 vsnprintf ( msg_concat, 8192, msg, arg_list );
68 debug_handler ( level, file, line, function, msg_concat );
74 * handler debug handler; NULL for default handler
76 void ped_debug_set_handler ( PedDebugHandler* handler )
78 debug_handler = ( handler ? handler : default_handler );
83 * Do not call this directly -- use PED_ASSERT() instead.
85 void ped_assert (const char* cond_text,
86 const char* file, int line, const char* function)
89 /* Print backtrace stack */
91 char **strings, **string;
92 int size = backtrace(stack, 20);
93 strings = backtrace_symbols(stack, size);
96 printf(_("Backtrace has %d calls on stack:\n"), size);
98 for (string = strings; size > 0; size--, string++)
99 printf(" %d: %s\n", size, *string);
105 /* Throw the exception */
106 ped_exception_throw (
109 _("Assertion (%s) at %s:%d in function %s() failed."),
110 cond_text, file, line, function);