* solve an inline problem with the gcc3.4 compiler used at SOLEIL
[hkl.git] / src / usage.c
blob084346852d7031e0851e576cf05caa8483e6d6d6
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.
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
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);
37 fputs("\n", stderr);
40 static NORETURN void die_builtin(const char *err, va_list params)
42 report("fatal: ", err, params);
43 exit(128);
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, ...)
68 va_list params;
70 va_start(params, err);
71 die_routine(err, params);
72 va_end(params);
75 void warning(const char *err, ...)
77 va_list params;
79 va_start(params, err);
80 warning_routine(err, params);
81 va_end(params);
84 void hkl_printbt(void)
86 void *array[20];
87 int size;
88 char **strings;
89 int i;
91 size = backtrace(array, 20);
92 strings = backtrace_symbols(array, size);
94 printf("Got a backtrace:\n");
95 for(i=0; i<size; ++i)
96 printf("#%i %s\n", i, strings[i]);
98 free(strings);
101 __inline__ void *_hkl_malloc(int size, const char *error)
103 void *tmp;
105 tmp = calloc(1, size);
106 if(!tmp)
107 die("%s", error);
109 return tmp;