1a45ae5f8SJohn Marino /* Shared general utility routines for GDB, the GNU debugger. 2a45ae5f8SJohn Marino 3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc. 4a45ae5f8SJohn Marino 5a45ae5f8SJohn Marino This file is part of GDB. 6a45ae5f8SJohn Marino 7a45ae5f8SJohn Marino This program is free software; you can redistribute it and/or modify 8a45ae5f8SJohn Marino it under the terms of the GNU General Public License as published by 9a45ae5f8SJohn Marino the Free Software Foundation; either version 3 of the License, or 10a45ae5f8SJohn Marino (at your option) any later version. 11a45ae5f8SJohn Marino 12a45ae5f8SJohn Marino This program is distributed in the hope that it will be useful, 13a45ae5f8SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 14a45ae5f8SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15a45ae5f8SJohn Marino GNU General Public License for more details. 16a45ae5f8SJohn Marino 17a45ae5f8SJohn Marino You should have received a copy of the GNU General Public License 18a45ae5f8SJohn Marino along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19a45ae5f8SJohn Marino 20a45ae5f8SJohn Marino #ifndef COMMON_UTILS_H 21a45ae5f8SJohn Marino #define COMMON_UTILS_H 22a45ae5f8SJohn Marino 23a45ae5f8SJohn Marino #include "config.h" 24a45ae5f8SJohn Marino #include "ansidecl.h" 25a45ae5f8SJohn Marino #include <stddef.h> 26a45ae5f8SJohn Marino #include <stdarg.h> 27a45ae5f8SJohn Marino 28a45ae5f8SJohn Marino extern void malloc_failure (long size) ATTRIBUTE_NORETURN; 29a45ae5f8SJohn Marino extern void internal_error (const char *file, int line, const char *, ...) 30a45ae5f8SJohn Marino ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 4); 31a45ae5f8SJohn Marino 32a45ae5f8SJohn Marino /* xmalloc(), xrealloc() and xcalloc() have already been declared in 33a45ae5f8SJohn Marino "libiberty.h". */ 34a45ae5f8SJohn Marino 35a45ae5f8SJohn Marino /* Like xmalloc, but zero the memory. */ 36a45ae5f8SJohn Marino void *xzalloc (size_t); 37a45ae5f8SJohn Marino 38a45ae5f8SJohn Marino void xfree (void *); 39a45ae5f8SJohn Marino 40a45ae5f8SJohn Marino /* Like asprintf and vasprintf, but return the string, throw an error 41a45ae5f8SJohn Marino if no memory. */ 42a45ae5f8SJohn Marino char *xstrprintf (const char *format, ...) ATTRIBUTE_PRINTF (1, 2); 43a45ae5f8SJohn Marino char *xstrvprintf (const char *format, va_list ap) 44a45ae5f8SJohn Marino ATTRIBUTE_PRINTF (1, 0); 45a45ae5f8SJohn Marino 46a45ae5f8SJohn Marino /* Like snprintf, but throw an error if the output buffer is too small. */ 47a45ae5f8SJohn Marino int xsnprintf (char *str, size_t size, const char *format, ...) 48a45ae5f8SJohn Marino ATTRIBUTE_PRINTF (3, 4); 49a45ae5f8SJohn Marino 50*ef5ccd6cSJohn Marino /* Make a copy of the string at PTR with LEN characters 51*ef5ccd6cSJohn Marino (and add a null character at the end in the copy). 52*ef5ccd6cSJohn Marino Uses malloc to get the space. Returns the address of the copy. */ 53*ef5ccd6cSJohn Marino 54*ef5ccd6cSJohn Marino char *savestring (const char *ptr, size_t len); 55*ef5ccd6cSJohn Marino 56a45ae5f8SJohn Marino #endif 57