aboutsummaryrefslogtreecommitdiff
path: root/libiberty/argv.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2009-10-09 04:49:52 +0000
committerDJ Delorie <dj@redhat.com>2009-10-09 04:49:52 +0000
commit79e314681214f07a627b172220ac49e1640ffe54 (patch)
tree4e418dc25b475bee7c770fba8ac2fd4009c202fa /libiberty/argv.c
parent287369626f415a12f53989914dc0499b6c96d1aa (diff)
downloadgdb-79e314681214f07a627b172220ac49e1640ffe54.zip
gdb-79e314681214f07a627b172220ac49e1640ffe54.tar.gz
gdb-79e314681214f07a627b172220ac49e1640ffe54.tar.bz2
merge from gcc
Diffstat (limited to 'libiberty/argv.c')
-rw-r--r--libiberty/argv.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/libiberty/argv.c b/libiberty/argv.c
index 38bd449..3084248 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -119,6 +119,24 @@ void freeargv (char **vector)
}
}
+static void
+consume_whitespace (const char **input)
+{
+ while (ISSPACE (**input))
+ {
+ (*input)++;
+ }
+}
+
+static int
+only_whitespace (const char* input)
+{
+ while (*input != EOS && ISSPACE (*input))
+ input++;
+
+ return (*input == EOS);
+}
+
/*
@deftypefn Extension char** buildargv (char *@var{sp})
@@ -179,10 +197,8 @@ char **buildargv (const char *input)
do
{
/* Pick off argv[argc] */
- while (ISBLANK (*input))
- {
- input++;
- }
+ consume_whitespace (&input);
+
if ((maxargc == 0) || (argc >= (maxargc - 1)))
{
/* argv needs initialization, or expansion */
@@ -278,10 +294,7 @@ char **buildargv (const char *input)
argc++;
argv[argc] = NULL;
- while (ISSPACE (*input))
- {
- input++;
- }
+ consume_whitespace (&input);
}
while (*input != EOS);
}
@@ -420,8 +433,17 @@ expandargv (int *argcp, char ***argvp)
goto error;
/* Add a NUL terminator. */
buffer[len] = '\0';
- /* Parse the string. */
- file_argv = buildargv (buffer);
+ /* If the file is empty or contains only whitespace, buildargv would
+ return a single empty argument. In this context we want no arguments,
+ instead. */
+ if (only_whitespace (buffer))
+ {
+ file_argv = (char **) xmalloc (sizeof (char *));
+ file_argv[0] = NULL;
+ }
+ else
+ /* Parse the string. */
+ file_argv = buildargv (buffer);
/* If *ARGVP is not already dynamically allocated, copy it. */
if (!argv_dynamic)
{
@@ -434,7 +456,7 @@ expandargv (int *argcp, char ***argvp)
}
/* Count the number of arguments. */
file_argc = 0;
- while (file_argv[file_argc] && *file_argv[file_argc])
+ while (file_argv[file_argc])
++file_argc;
/* Now, insert FILE_ARGV into ARGV. The "+1" below handles the
NULL terminator at the end of ARGV. */