]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libiberty/argv.c
cplus-dem.c (demangle_signature): Don't look for return types on constructors.
[thirdparty/gcc.git] / libiberty / argv.c
index 60694f919bb94bfd7d1a5bda9a3d3af70676faa0..824a02988363a30b0fc98e5f0e370825d315afb9 100644 (file)
@@ -68,6 +68,63 @@ extern char *strdup ();              /* Duplicate a string */
 #define INITIAL_MAXARGC 8      /* Number of args + NULL in initial argv */
 
 
+/*
+
+NAME
+
+       dupargv -- duplicate an argument vector
+
+SYNOPSIS
+
+       char **dupargv (vector)
+       char **vector;
+
+DESCRIPTION
+
+       Duplicate an argument vector.  Simply scans through the
+       vector, duplicating each argument argument until the
+       terminating NULL is found.
+
+RETURNS
+
+       Returns a pointer to the argument vector if
+       successful. Returns NULL if there is insufficient memory to
+       complete building the argument vector.
+
+*/
+
+char **
+dupargv (argv)
+     char **argv;
+{
+  int argc;
+  char **copy;
+  
+  if (argv == NULL)
+    return NULL;
+  
+  /* the vector */
+  for (argc = 0; argv[argc] != NULL; argc++);
+  copy = (char **) malloc ((argc + 1) * sizeof (char *));
+  if (copy == NULL)
+    return NULL;
+  
+  /* the strings */
+  for (argc = 0; argv[argc] != NULL; argc++)
+    {
+      int len = strlen (argv[argc]);
+      copy[argc] = malloc (sizeof (char *) * (len + 1));
+      if (copy[argc] == NULL)
+       {
+         freeargv (copy);
+         return NULL;
+       }
+      strcpy (copy[argc], argv[argc]);
+    }
+  copy[argc] = NULL;
+  return copy;
+}
+
 /*
 
 NAME