/* Create and destroy argument vectors (argv's)
- Copyright (C) 1992, 2001, 2010 Free Software Foundation, Inc.
+ Copyright (C) 1992, 2001, 2010, 2012 Free Software Foundation, Inc.
Written by Fred Fish @ Cygnus Support
This file is part of the libiberty library.
/* the vector */
for (argc = 0; argv[argc] != NULL; argc++);
- copy = (char **) malloc ((argc + 1) * sizeof (char *));
- if (copy == NULL)
- return NULL;
-
+ copy = (char **) xmalloc ((argc + 1) * sizeof (char *));
+
/* the strings */
for (argc = 0; argv[argc] != NULL; argc++)
{
int len = strlen (argv[argc]);
- copy[argc] = (char *) malloc (len + 1);
- if (copy[argc] == NULL)
- {
- freeargv (copy);
- return NULL;
- }
+ copy[argc] = (char *) xmalloc (len + 1);
strcpy (copy[argc], argv[argc]);
}
copy[argc] = NULL;
@code{NULL} element.
All of the memory for the pointer array and copies of the string
-is obtained from @code{malloc}. All of the memory can be returned to the
+is obtained from @code{xmalloc}. All of the memory can be returned to the
system with the single function call @code{freeargv}, which takes the
returned result of @code{buildargv}, as it's argument.
if (argv == NULL)
{
maxargc = INITIAL_MAXARGC;
- nargv = (char **) malloc (maxargc * sizeof (char *));
+ nargv = (char **) xmalloc (maxargc * sizeof (char *));
}
else
{
maxargc *= 2;
- nargv = (char **) realloc (argv, maxargc * sizeof (char *));
- }
- if (nargv == NULL)
- {
- if (argv != NULL)
- {
- freeargv (argv);
- argv = NULL;
- }
- break;
+ nargv = (char **) xrealloc (argv, maxargc * sizeof (char *));
}
argv = nargv;
argv[argc] = NULL;
}
}
*arg = EOS;
- argv[argc] = strdup (copybuf);
- if (argv[argc] == NULL)
- {
- freeargv (argv);
- argv = NULL;
- break;
- }
+ argv[argc] = xstrdup (copybuf);
argc++;
argv[argc] = NULL;
file_argv = buildargv (buffer);
/* If *ARGVP is not already dynamically allocated, copy it. */
if (!argv_dynamic)
- {
- *argvp = dupargv (*argvp);
- if (!*argvp)
- {
- fputs ("\nout of memory\n", stderr);
- xexit (1);
- }
- }
+ *argvp = dupargv (*argvp);
/* Count the number of arguments. */
file_argc = 0;
while (file_argv[file_argc])