From 6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:29:51 +0200 Subject: Adding upstream version 2.06. Signed-off-by: Daniel Baumann --- util/grub-file.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 util/grub-file.c (limited to 'util/grub-file.c') diff --git a/util/grub-file.c b/util/grub-file.c new file mode 100644 index 0000000..b2e7dd6 --- /dev/null +++ b/util/grub-file.c @@ -0,0 +1,106 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2012,2013 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define _GNU_SOURCE 1 + +#include +#include +#include +#include +#include + +#include "progname.h" + +void grub_file_init (void); +void grub_host_init (void); +void grub_hostfs_init (void); + +int +main (int argc, char *argv[]) +{ + char **argv2; + int i; + int had_file = 0, had_separator = 0; + grub_command_t cmd; + grub_err_t err; + + grub_util_host_init (&argc, &argv); + + argv2 = xcalloc (argc, sizeof (argv2[0])); + + if (argc == 2 && strcmp (argv[1], "--version") == 0) + { + printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); + } + + for (i = 1; i < argc; i++) + { + if (argv[i][0] == '-' && argv[i][1] == '-' + && argv[i][2] == '\0' && !had_separator) + { + had_separator = 1; + argv2[i - 1] = xstrdup (argv[i]); + continue; + } + if (argv[i][0] == '-' && !had_separator) + { + argv2[i - 1] = xstrdup (argv[i]); + continue; + } + if (had_file) + grub_util_error ("one argument expected"); + argv2[i - 1] = grub_canonicalize_file_name (argv[i]); + if (!argv2[i - 1]) + { + grub_util_error (_("cannot open `%s': %s"), argv[i], + strerror (errno)); + } + had_file = 1; + } + argv2[i - 1] = NULL; + + /* Initialize all modules. */ + grub_init_all (); + grub_file_init (); + grub_hostfs_init (); + grub_host_init (); + + grub_env_set ("root", "host"); + + cmd = grub_command_find ("file"); + if (! cmd) + grub_util_error (_("can't find command `%s'"), "file"); + + err = (cmd->func) (cmd, argc - 1, argv2); + if (err && err != GRUB_ERR_TEST_FAILURE) + grub_print_error (); + return err; +} -- cgit v1.2.3