diff options
author | Joel Brobecker <brobecker@adacore.com> | 2013-11-11 09:19:32 +0400 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2013-11-14 14:31:42 +0400 |
commit | b5be8ce022f894831b133b3b424238d8058eb29e (patch) | |
tree | 4112aeb43628e418fecbb68a8cd46c5ae116f213 /gdb/cli/cli-utils.c | |
parent | 671afef641d8cf0672e36d7afeb053c8d01c294e (diff) | |
download | fsf-binutils-gdb-b5be8ce022f894831b133b3b424238d8058eb29e.zip fsf-binutils-gdb-b5be8ce022f894831b133b3b424238d8058eb29e.tar.gz fsf-binutils-gdb-b5be8ce022f894831b133b3b424238d8058eb29e.tar.bz2 |
New function cli-utils.c:extract_arg_const
This function provides the exact same functionality as extract_arg,
except that it takes a "const char**" instead of a "char **".
It allows us also to re-implement extract_arg almost as a simple
wrapper around the new function.
gdb/ChangeLog:
Pedro Alves <palves@redhat.com>
Joel Brobecker <brobecker@adacore.com>
* cli/cli-utils.h (extract_arg_const): Add declaration.
* cli/cli-utils.c (extract_arg_const): New function.
(extract_arg): Reimplement using extract_arg_const.
Diffstat (limited to 'gdb/cli/cli-utils.c')
-rw-r--r-- | gdb/cli/cli-utils.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index f74e6b1..316cf4f 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -261,30 +261,39 @@ remove_trailing_whitespace (const char *start, char *s) /* See documentation in cli-utils.h. */ char * -extract_arg (char **arg) +extract_arg_const (const char **arg) { - char *result, *copy; + const char *result; if (!*arg) return NULL; /* Find the start of the argument. */ - *arg = skip_spaces (*arg); + *arg = skip_spaces_const (*arg); if (!**arg) return NULL; result = *arg; /* Find the end of the argument. */ - *arg = skip_to_space (*arg + 1); + *arg = skip_to_space_const (*arg + 1); if (result == *arg) return NULL; - copy = xmalloc (*arg - result + 1); - memcpy (copy, result, *arg - result); - copy[*arg - result] = '\0'; + return savestring (result, *arg - result); +} + +/* See documentation in cli-utils.h. */ + +char * +extract_arg (char **arg) +{ + const char *arg_const = *arg; + char *result; - return copy; + result = extract_arg_const (&arg_const); + *arg += arg_const - *arg; + return result; } /* See documentation in cli-utils.h. */ |