[contrib] factorize the [Double] -> [Angle Double] transformation
[hkl.git] / hkl / hkl-macros.c
blobc7ec0eaebac3e4f76f4429d923cdaa8070e2bcfc
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-2014 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>
22 #include <execinfo.h> // for backtrace, etc
23 #include <stdio.h> // for fprintf, printf, stderr
24 #include <stdlib.h> // for calloc, exit, free
26 #ifndef _MSC_VER
27 void hkl_printbt(void)
29 void *array[20];
30 int size;
31 char **strings;
32 int i;
34 size = backtrace(array, 20);
35 strings = backtrace_symbols(array, size);
37 printf("Got a backtrace:\n");
38 for(i=0; i<size; ++i)
39 fprintf(stderr, "#%i %s\n", i, strings[i]);
41 free(strings);
43 #else
44 int vasprintf(char **strp, const char *fmt, va_list ap)
46 int len;
47 char *buffer;
49 len = vsnprintf(*strp, 0, fmt, ap);
50 buffer = malloc(len);
51 vsnprintf(buffer, len-1, fmt, ap);
52 *strp = buffer;
54 return len;
56 #endif
58 void *_hkl_malloc(int size, const char *error)
60 void *tmp;
62 tmp = calloc(1, size);
63 if(!tmp){
64 fprintf(stderr, "%s", error);
65 exit(128);
68 return tmp;