1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2003-2010 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
23 * Copyright (C) Linus Torvalds, 2005-2006.
24 * Copyright (C) Synchrotron Soleil 2007-2008.
31 #include <hkl/hkl-macros.h>
33 static void report(const char *prefix
, const char *err
, va_list params
)
35 fputs(prefix
, stderr
);
36 vfprintf(stderr
, err
, params
);
40 static NORETURN
void die_builtin(const char *err
, va_list params
)
42 report("fatal: ", err
, params
);
45 static void warning_builtin(const char *err
, va_list params
)
47 report("warning: ", err
, params
);
51 /* If we are in a dlopen()ed .so write to a global variable would segfault
52 * (ugh), so keep things static. */
53 static void (*die_routine
)(const char *err
, va_list params
) NORETURN
= die_builtin
;
54 static void (*warning_routine
)(const char *err
, va_list params
) = warning_builtin
;
56 void set_die_routine(void (*routine
)(const char *err
, va_list params
) NORETURN
)
58 die_routine
= routine
;
61 void set_warning_routine(void (*routine
)(const char *err
, va_list params
))
63 warning_routine
= routine
;
66 void die(const char *err
, ...)
70 va_start(params
, err
);
71 die_routine(err
, params
);
75 void warning(const char *err
, ...)
79 va_start(params
, err
);
80 warning_routine(err
, params
);
84 void hkl_printbt(void)
91 size
= backtrace(array
, 20);
92 strings
= backtrace_symbols(array
, size
);
94 printf("Got a backtrace:\n");
96 printf("#%i %s\n", i
, strings
[i
]);
101 __inline__
void *_hkl_malloc(int size
, const char *error
)
105 tmp
= calloc(1, size
);