]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
return arg count from grub_script_execute_arglist_to_argv
authorBVK Chaitanya <bvk.groups@gmail.com>
Sat, 23 Jan 2010 03:42:46 +0000 (09:12 +0530)
committerBVK Chaitanya <bvk.groups@gmail.com>
Sat, 23 Jan 2010 03:42:46 +0000 (09:12 +0530)
include/grub/script_sh.h
script/execute.c

index 5ada7c7e51d06523127fec50cbcbdcc23d2b0a3e..c8c610d7b72e642bcc834fe7c7fde117bf5f73c2 100644 (file)
@@ -300,6 +300,6 @@ int grub_script_function_call (grub_script_function_t func,
                               int argc, char **args);
 
 char **
-grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist);
+grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count);
 
 #endif /* ! GRUB_NORMAL_PARSER_HEADER */
index 4197598fbe2bdc5c1f69b97f44a936952b68e1c1..5d60e9f8c24e0f5ee86f12b981fe0fcc7b945090 100644 (file)
@@ -37,7 +37,7 @@ grub_script_execute_cmd (struct grub_script_cmd *cmd)
 
 /* Expand arguments in ARGLIST into multiple arguments.  */
 char **
-grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist)
+grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count)
 {
   int i;
   int oom;
@@ -162,7 +162,6 @@ grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist)
       if (!empty)
        push (0);
     }
-  push (0); /* Ensure argv[argc] == 0.  */
 
   if (oom)
     {
@@ -172,6 +171,9 @@ grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist)
       argv = 0;
     }
 
+  if (argv)
+    *count = argc - 1;
+
   return argv;
 }
 
@@ -190,7 +192,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
   char *cmdname;
 
   /* Lookup the command.  */
-  args = grub_script_execute_arglist_to_argv (cmdline->arglist);
+  args = grub_script_execute_arglist_to_argv (cmdline->arglist, &argcount);
   if (!args)
     return grub_errno;
 
@@ -228,9 +230,6 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
        }
     }
 
-  /* Count argv size.  */
-  for (argcount = 0; args[argcount]; argcount++);
-
   /* Execute the GRUB command or function.  */
   if (grubcmd)
     ret = (grubcmd->func) (grubcmd, argcount - 1, args + 1);
@@ -296,11 +295,9 @@ grub_script_execute_menuentry (struct grub_script_cmd *cmd)
 
   if (cmd_menuentry->arglist)
     {
-      args = grub_script_execute_arglist_to_argv (cmd_menuentry->arglist);
+      args = grub_script_execute_arglist_to_argv (cmd_menuentry->arglist, &argcount);
       if (!args)
        return grub_errno;
-
-      for (argcount = 0; args[argcount]; argcount++);
     }
 
   grub_normal_add_menu_entry (argcount, (const char **) args,