/* Shared general utility routines for GDB, the GNU debugger.
- Copyright (C) 1986-2014 Free Software Foundation, Inc.
+ Copyright (C) 1986-2016 Free Software Foundation, Inc.
This file is part of GDB.
#ifndef COMMON_UTILS_H
#define COMMON_UTILS_H
-#include "ansidecl.h"
+#include <string>
/* If possible, define FUNCTION_NAME, a macro containing the name of
the function being defined. Since this macro may not always be
#endif
#endif
-extern void malloc_failure (long size) ATTRIBUTE_NORETURN;
-extern void internal_error (const char *file, int line, const char *, ...)
- ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 4);
-
/* xmalloc(), xrealloc() and xcalloc() have already been declared in
"libiberty.h". */
int xsnprintf (char *str, size_t size, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
+/* Returns a std::string built from a printf-style format string. */
+std::string string_printf (const char* fmt, ...)
+ ATTRIBUTE_PRINTF (1, 2);
+
/* Make a copy of the string at PTR with LEN characters
(and add a null character at the end in the copy).
Uses malloc to get the space. Returns the address of the copy. */
char *savestring (const char *ptr, size_t len);
+/* The strerror() function can return NULL for errno values that are
+ out of range. Provide a "safe" version that always returns a
+ printable string. */
+
+extern char *safe_strerror (int);
+
+/* Return non-zero if the start of STRING matches PATTERN, zero
+ otherwise. */
+
+static inline int
+startswith (const char *string, const char *pattern)
+{
+ return strncmp (string, pattern, strlen (pattern)) == 0;
+}
+
+ULONGEST strtoulst (const char *num, const char **trailer, int base);
+
+/* Skip leading whitespace characters in INP, returning an updated
+ pointer. If INP is NULL, return NULL. */
+
+extern char *skip_spaces (char *inp);
+
+/* A const-correct version of the above. */
+
+extern const char *skip_spaces_const (const char *inp);
+
+/* Skip leading non-whitespace characters in INP, returning an updated
+ pointer. If INP is NULL, return NULL. */
+
+#define skip_to_space(INP) ((char *) skip_to_space_const (INP))
+
+/* A const-correct version of the above. */
+
+extern const char *skip_to_space_const (const char *inp);
+
#endif