* util/grub-menulst2cfg.c (main): Check return value of fwrite.

* util/grub-mklayout.c (write_file): Likewise. New argument fname.
	All users updated.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-05-10 09:39:11 +02:00
parent 9133fd053f
commit 8aeb18379b
3 changed files with 31 additions and 9 deletions

View file

@ -1,3 +1,9 @@
2012-05-10 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-menulst2cfg.c (main): Check return value of fwrite.
* util/grub-mklayout.c (write_file): Likewise. New argument fname.
Allusers updated.
2012-05-10 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub.d/20_linux_xen.in: Update initrd list based on 10_linux.in

View file

@ -35,6 +35,7 @@ main (int argc, char **argv)
size_t bufsize = 0;
char *suffix = xstrdup ("");
int suffixlen = 0;
const char *out_fname = 0;
if (argc >= 2 && argv[1][0] == '-')
{
@ -66,6 +67,7 @@ main (int argc, char **argv)
argv[2], strerror (errno));
return 1;
}
out_fname = argv[2];
}
else
out = stdout;
@ -109,7 +111,14 @@ main (int argc, char **argv)
if (entryname)
fprintf (out, "}\n\n");
fwrite (suffix, 1, suffixlen, out);
if (fwrite (suffix, 1, suffixlen, out) != suffixlen)
{
if (out_fname)
grub_util_error ("cannot write to `%s': %s",
out_fname, strerror (errno));
else
grub_util_error ("cannot write to the stdout: %s", strerror (errno));
}
free (buf);
free (suffix);

View file

@ -310,7 +310,7 @@ get_grub_code (char *layout_code, int shift)
}
static void
write_file (FILE *out, struct grub_keyboard_layout *layout)
write_file (FILE *out, const char *fname, struct grub_keyboard_layout *layout)
{
grub_uint32_t version;
unsigned i;
@ -332,14 +332,21 @@ write_file (FILE *out, struct grub_keyboard_layout *layout)
layout->keyboard_map_shift_l3[i]
= grub_cpu_to_le32(layout->keyboard_map_shift_l3[i]);
fwrite (GRUB_KEYBOARD_LAYOUTS_FILEMAGIC, 1,
GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE, out);
fwrite (&version, sizeof (version), 1, out);
fwrite (layout, 1, sizeof (*layout), out);
if (fwrite (GRUB_KEYBOARD_LAYOUTS_FILEMAGIC, 1,
GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE, out)
!= GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE
|| fwrite (&version, sizeof (version), 1, out) != 1
|| fwrite (layout, 1, sizeof (*layout), out) != sizeof (*layout))
{
if (fname)
grub_util_error ("cannot write to `%s': %s", fname, strerror (errno));
else
grub_util_error ("cannot write to the stdout: %s", strerror (errno));
}
}
static void
write_keymaps (FILE *in, FILE *out)
write_keymaps (FILE *in, FILE *out, const char *out_filename)
{
struct grub_keyboard_layout layout;
char line[2048];
@ -413,7 +420,7 @@ write_keymaps (FILE *in, FILE *out)
add_special_keys (&layout);
write_file (out, &layout);
write_file (out, out_filename, &layout);
}
static error_t
@ -489,7 +496,7 @@ main (int argc, char *argv[])
strerror (errno));
}
write_keymaps (in, out);
write_keymaps (in, out, arguments.output);
if (in != stdin)
fclose (in);