2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
28 #include <sys/types.h>
32 #include <grub/kernel.h>
34 #include <grub/misc.h>
35 #include <grub/cache.h>
36 #include <grub/emu/misc.h>
37 #include <grub/util/misc.h>
39 #include <grub/term.h>
40 #include <grub/time.h>
41 #include <grub/i18n.h>
42 #include <grub/script_sh.h>
43 #include <grub/emu/hostfile.h>
45 #define ENABLE_RELOCATABLE 0
47 const char *program_name
= GRUB_BUILD_PROGRAM_NAME
;
54 grub_err_printf (const char *fmt
, ...)
60 ret
= vfprintf (stderr
, fmt
, ap
);
68 grub_util_get_path (const char *dir
, const char *file
)
72 path
= (char *) xmalloc (strlen (dir
) + 1 + strlen (file
) + 1);
73 sprintf (path
, "%s/%s", dir
, file
);
78 grub_util_read_image (const char *path
)
84 grub_util_info ("reading %s", path
);
86 size
= grub_util_get_image_size (path
);
87 img
= (char *) xmalloc (size
);
89 fp
= grub_util_fopen (path
, "rb");
91 grub_util_error (_("cannot open `%s': %s"), path
,
94 if (fread (img
, 1, size
, fp
) != size
)
95 grub_util_error (_("cannot read `%s': %s"), path
,
104 grub_util_write_image_at (const void *img
, size_t size
, off_t offset
, FILE *out
,
107 grub_util_info ("writing 0x%" GRUB_HOST_PRIxLONG_LONG
" bytes at offset 0x%"
108 GRUB_HOST_PRIxLONG_LONG
,
109 (unsigned long long) size
, (unsigned long long) offset
);
110 if (fseeko (out
, offset
, SEEK_SET
) == -1)
111 grub_util_error (_("cannot seek `%s': %s"),
112 name
, strerror (errno
));
113 if (fwrite (img
, 1, size
, out
) != size
)
114 grub_util_error (_("cannot write to `%s': %s"),
115 name
, strerror (errno
));
119 grub_util_write_image (const char *img
, size_t size
, FILE *out
,
122 grub_util_info ("writing 0x%" GRUB_HOST_PRIxLONG_LONG
" bytes", (unsigned long long) size
);
123 if (fwrite (img
, 1, size
, out
) != size
)
126 grub_util_error (_("cannot write to the stdout: %s"),
129 grub_util_error (_("cannot write to `%s': %s"),
130 name
, strerror (errno
));
135 grub_script_execute_cmdline (struct grub_script_cmd
*cmd
__attribute__ ((unused
)))
141 grub_script_execute_cmdlist (struct grub_script_cmd
*cmd
__attribute__ ((unused
)))
147 grub_script_execute_cmdif (struct grub_script_cmd
*cmd
__attribute__ ((unused
)))
153 grub_script_execute_cmdfor (struct grub_script_cmd
*cmd
__attribute__ ((unused
)))
159 grub_script_execute_cmdwhile (struct grub_script_cmd
*cmd
__attribute__ ((unused
)))
165 grub_script_execute (struct grub_script
*script
)
167 if (script
== 0 || script
->cmd
== 0)
170 return script
->cmd
->exec (script
->cmd
);
186 grub_xputs_real (const char *str
)
191 void (*grub_xputs
) (const char *str
) = grub_xputs_real
;
194 grub_dl_ref (grub_dl_t mod
)
201 grub_dl_unref (grub_dl_t mod
)
207 /* Some functions that we don't use. */
209 grub_mm_init_region (void *addr
__attribute__ ((unused
)),
210 grub_size_t size
__attribute__ ((unused
)))
215 grub_register_exported_symbols (void)
219 /* Used in comparison of arrays of strings with qsort */
221 grub_qsort_strcmp (const void *p1
, const void *p2
)
223 return strcmp(*(char *const *)p1
, *(char *const *)p2
);