GDBserver
common-utils.h
Go to the documentation of this file.
1 /* Shared general utility routines for GDB, the GNU debugger.
2 
3  Copyright (C) 1986-2015 Free Software Foundation, Inc.
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 /* If possible, define FUNCTION_NAME, a macro containing the name of
24  the function being defined. Since this macro may not always be
25  defined, all uses must be protected by appropriate macro definition
26  checks (Eg: "#ifdef FUNCTION_NAME").
27 
28  Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
29  which contains the name of the function currently being defined.
30  This is broken in G++ before version 2.6.
31  C9x has a similar variable called __func__, but prefer the GCC one since
32  it demangles C++ function names. */
33 #if (GCC_VERSION >= 2004)
34 #define FUNCTION_NAME __PRETTY_FUNCTION__
35 #else
36 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
37 #define FUNCTION_NAME __func__ /* ARI: func */
38 #endif
39 #endif
40 
41 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
42  "libiberty.h". */
43 
44 /* Like xmalloc, but zero the memory. */
45 void *xzalloc (size_t);
46 
47 void xfree (void *);
48 
49 /* Like asprintf and vasprintf, but return the string, throw an error
50  if no memory. */
51 char *xstrprintf (const char *format, ...) ATTRIBUTE_PRINTF (1, 2);
52 char *xstrvprintf (const char *format, va_list ap)
53  ATTRIBUTE_PRINTF (1, 0);
54 
55 /* Like snprintf, but throw an error if the output buffer is too small. */
56 int xsnprintf (char *str, size_t size, const char *format, ...)
57  ATTRIBUTE_PRINTF (3, 4);
58 
59 /* Make a copy of the string at PTR with LEN characters
60  (and add a null character at the end in the copy).
61  Uses malloc to get the space. Returns the address of the copy. */
62 
63 char *savestring (const char *ptr, size_t len);
64 
65 /* The strerror() function can return NULL for errno values that are
66  out of range. Provide a "safe" version that always returns a
67  printable string. */
68 
69 extern char *safe_strerror (int);
70 
71 /* Return non-zero if the start of STRING matches PATTERN, zero
72  otherwise. */
73 
74 static inline int
75 startswith (const char *string, const char *pattern)
76 {
77  return strncmp (string, pattern, strlen (pattern)) == 0;
78 }
79 
80 ULONGEST strtoulst (const char *num, const char **trailer, int base);
81 
82 /* Skip leading whitespace characters in INP, returning an updated
83  pointer. If INP is NULL, return NULL. */
84 
85 extern char *skip_spaces (char *inp);
86 
87 /* A const-correct version of the above. */
88 
89 extern const char *skip_spaces_const (const char *inp);
90 
91 /* Skip leading non-whitespace characters in INP, returning an updated
92  pointer. If INP is NULL, return NULL. */
93 
94 #define skip_to_space(INP) ((char *) skip_to_space_const (INP))
95 
96 /* A const-correct version of the above. */
97 
98 extern const char *skip_to_space_const (const char *inp);
99 
100 #endif
const char * skip_spaces_const(const char *inp)
Definition: common-utils.c:271
const char * skip_to_space_const(const char *inp)
Definition: common-utils.c:283
char char int char * savestring(const char *ptr, size_t len)
Definition: common-utils.c:148
char char int xsnprintf(char *str, size_t size, const char *format,...) ATTRIBUTE_PRINTF(3
char * skip_spaces(char *inp)
Definition: common-utils.c:259
void xfree(void *)
Definition: common-utils.c:97
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:75
char * xstrprintf(const char *format,...) ATTRIBUTE_PRINTF(1
static void ATTRIBUTE_PRINTF(1, 2)
Definition: agent.c:31
void * xzalloc(size_t)
Definition: common-utils.c:91
char * safe_strerror(int)
ULONGEST strtoulst(const char *num, const char **trailer, int base)
Definition: common-utils.c:188
unsigned long long ULONGEST
Definition: common-types.h:53
char char * xstrvprintf(const char *format, va_list ap) ATTRIBUTE_PRINTF(1