Commit | Line | Data |
---|---|---|
d26e3629 KY |
1 | /* Shared general utility routines for GDB, the GNU debugger. |
2 | ||
ecd75fc8 | 3 | Copyright (C) 1986-2014 Free Software Foundation, Inc. |
d26e3629 KY |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #ifndef COMMON_UTILS_H | |
21 | #define COMMON_UTILS_H | |
22 | ||
23 | #include "config.h" | |
24 | #include "ansidecl.h" | |
25 | #include <stddef.h> | |
26 | #include <stdarg.h> | |
27 | ||
3a80edfc JB |
28 | /* If possible, define FUNCTION_NAME, a macro containing the name of |
29 | the function being defined. Since this macro may not always be | |
30 | defined, all uses must be protected by appropriate macro definition | |
31 | checks (Eg: "#ifdef FUNCTION_NAME"). | |
32 | ||
33 | Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__' | |
df049a58 DE |
34 | which contains the name of the function currently being defined. |
35 | This is broken in G++ before version 2.6. | |
36 | C9x has a similar variable called __func__, but prefer the GCC one since | |
37 | it demangles C++ function names. */ | |
38 | #if (GCC_VERSION >= 2004) | |
39 | #define FUNCTION_NAME __PRETTY_FUNCTION__ | |
40 | #else | |
41 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L | |
46bbb3ed | 42 | #define FUNCTION_NAME __func__ /* ARI: func */ |
df049a58 DE |
43 | #endif |
44 | #endif | |
45 | ||
d26e3629 KY |
46 | extern void malloc_failure (long size) ATTRIBUTE_NORETURN; |
47 | extern void internal_error (const char *file, int line, const char *, ...) | |
48 | ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 4); | |
49 | ||
50 | /* xmalloc(), xrealloc() and xcalloc() have already been declared in | |
51 | "libiberty.h". */ | |
52 | ||
53 | /* Like xmalloc, but zero the memory. */ | |
54 | void *xzalloc (size_t); | |
55 | ||
56 | void xfree (void *); | |
57 | ||
58 | /* Like asprintf and vasprintf, but return the string, throw an error | |
59 | if no memory. */ | |
60 | char *xstrprintf (const char *format, ...) ATTRIBUTE_PRINTF (1, 2); | |
61 | char *xstrvprintf (const char *format, va_list ap) | |
62 | ATTRIBUTE_PRINTF (1, 0); | |
63 | ||
d26e3629 KY |
64 | /* Like snprintf, but throw an error if the output buffer is too small. */ |
65 | int xsnprintf (char *str, size_t size, const char *format, ...) | |
66 | ATTRIBUTE_PRINTF (3, 4); | |
67 | ||
baea0dae PA |
68 | /* Make a copy of the string at PTR with LEN characters |
69 | (and add a null character at the end in the copy). | |
70 | Uses malloc to get the space. Returns the address of the copy. */ | |
71 | ||
72 | char *savestring (const char *ptr, size_t len); | |
73 | ||
d26e3629 | 74 | #endif |