Add a wrapper for fopen. On unix-like systems just pass-through. On

windows use unicode version.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-10-13 20:36:28 +02:00
parent ae5540d3d4
commit bb338aaf24
27 changed files with 97 additions and 41 deletions

View file

@ -119,7 +119,7 @@ create_envblk_file (const char *name)
buf = xmalloc (DEFAULT_ENVBLK_SIZE);
namenew = xasprintf ("%s.new", name);
fp = fopen (namenew, "wb");
fp = grub_util_fopen (namenew, "wb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), namenew,
strerror (errno));
@ -149,12 +149,12 @@ open_envblk_file (const char *name)
size_t size;
grub_envblk_t envblk;
fp = fopen (name, "rb");
fp = grub_util_fopen (name, "rb");
if (! fp)
{
/* Create the file implicitly. */
create_envblk_file (name);
fp = fopen (name, "rb");
fp = grub_util_fopen (name, "rb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), name,
strerror (errno));
@ -208,7 +208,7 @@ write_envblk (const char *name, grub_envblk_t envblk)
{
FILE *fp;
fp = fopen (name, "wb");
fp = grub_util_fopen (name, "wb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), name,
strerror (errno));

View file

@ -200,7 +200,7 @@ cmd_cp (char *src, const char *dest)
.dest = dest
};
ctx.ff = fopen (dest, "wb");
ctx.ff = grub_util_fopen (dest, "wb");
if (ctx.ff == NULL)
{
grub_util_error (_("cannot open OS file `%s': %s"), dest,
@ -310,7 +310,7 @@ cmd_cmp (char *src, char *dest)
return;
}
ff = fopen (dest, "rb");
ff = grub_util_fopen (dest, "rb");
if (ff == NULL)
{
grub_util_error (_("OS file %s open error: %s"), dest,
@ -562,7 +562,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
FILE *f;
ssize_t real_size;
grub_uint8_t buf[1024];
f = fopen (arg, "rb");
f = grub_util_fopen (arg, "rb");
if (!f)
{
printf (_("%s: error:"), program_name);

View file

@ -184,19 +184,19 @@ main (int argc, char *argv[])
exit(1);
}
in32 = fopen (arguments.input32, "r");
in32 = grub_util_fopen (arguments.input32, "r");
if (!in32)
grub_util_error (_("cannot open `%s': %s"), arguments.input32,
strerror (errno));
in64 = fopen (arguments.input64, "r");
in64 = grub_util_fopen (arguments.input64, "r");
if (!in64)
grub_util_error (_("cannot open `%s': %s"), arguments.input64,
strerror (errno));
if (arguments.output)
out = fopen (arguments.output, "wb");
out = grub_util_fopen (arguments.output, "wb");
else
out = stdout;

View file

@ -52,13 +52,13 @@ main (int argc, char **argv)
"Convert Mach-O into raw image\n", argv[0]);
return 0;
}
in = fopen (argv[1 + do_bss], "rb");
in = grub_util_fopen (argv[1 + do_bss], "rb");
if (! in)
{
printf ("Couldn't open %s\n", argv[1 + do_bss]);
return 1;
}
out = fopen (argv[2 + do_bss], "wb");
out = grub_util_fopen (argv[2 + do_bss], "wb");
if (! out)
{
fclose (in);

View file

@ -47,7 +47,7 @@ main (int argc, char **argv)
if (argc >= 2)
{
in = fopen (argv[1], "r");
in = grub_util_fopen (argv[1], "r");
if (!in)
{
fprintf (stderr, _("cannot open `%s': %s"),
@ -60,7 +60,7 @@ main (int argc, char **argv)
if (argc >= 3)
{
out = fopen (argv[2], "w");
out = grub_util_fopen (argv[2], "w");
if (!out)
{
if (in != stdin)

View file

@ -55,6 +55,10 @@
#include "progname.h"
#endif
#ifdef GRUB_BUILD
#define grub_util_fopen fopen
#endif
#define GRUB_FONT_DEFAULT_SIZE 16
#define GRUB_FONT_RANGE_BLOCK 1024
@ -785,7 +789,7 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
int offset;
struct grub_glyph_info *cur;
file = fopen (output_file, "wb");
file = grub_util_fopen (output_file, "wb");
if (! file)
grub_util_error (_("cannot write to `%s': %s"), output_file,
strerror (errno));

View file

@ -2052,7 +2052,7 @@ main (int argc, char *argv[])
if (arguments.output)
{
fp = fopen (arguments.output, "wb");
fp = grub_util_fopen (arguments.output, "wb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), arguments.output,
strerror (errno));

View file

@ -482,7 +482,7 @@ main (int argc, char *argv[])
}
if (arguments.input)
in = fopen (arguments.input, "r");
in = grub_util_fopen (arguments.input, "r");
else
in = stdin;
@ -491,7 +491,7 @@ main (int argc, char *argv[])
strerror (errno));
if (arguments.output)
out = fopen (arguments.output, "wb");
out = grub_util_fopen (arguments.output, "wb");
else
out = stdout;

View file

@ -474,7 +474,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
FILE *f;
ssize_t real_size;
grub_uint8_t buf[1024];
f = fopen (arg, "rb");
f = grub_util_fopen (arg, "rb");
if (!f)
{
printf (_("%s: error:"), program_name);

View file

@ -478,7 +478,7 @@ main (int argc, char *argv[])
out = in;
image = grub_util_read_image (in);
fp = fopen (out, "wb");
fp = grub_util_fopen (out, "wb");
if (! fp)
grub_util_error ("cannot open %s", out);

View file

@ -236,7 +236,7 @@ main (int argc, char *argv[])
text = arguments.text;
else
{
FILE *in = fopen (arguments.input, "r");
FILE *in = grub_util_fopen (arguments.input, "r");
size_t s;
if (!in)
grub_util_error (_("cannot open `%s': %s"), arguments.input,
@ -253,7 +253,7 @@ main (int argc, char *argv[])
}
if (arguments.output)
out = fopen (arguments.output, "wb");
out = grub_util_fopen (arguments.output, "wb");
else
out = stdout;
if (!out)

View file

@ -164,7 +164,7 @@ main (int argc, char *argv[])
}
else
{
ctx.file = fopen (ctx.arguments.filename, "r");
ctx.file = grub_util_fopen (ctx.arguments.filename, "r");
if (! ctx.file)
{
char *program = xstrdup(program_name);

View file

@ -662,14 +662,14 @@ unable_to_embed:
FILE *dump;
FILE *dump2;
dump = fopen ("dump.img", "wb");
dump = grub_util_fopen ("dump.img", "wb");
if (dump)
{
fwrite (tmp_img, 1, core_size, dump);
fclose (dump);
}
dump2 = fopen ("dump2.img", "wb");
dump2 = grub_util_fopen ("dump2.img", "wb");
if (dump2)
{
fwrite (core_img, 1, core_size, dump2);
@ -731,7 +731,7 @@ unable_to_embed:
/* Write the first two sectors of the core image onto the disk. */
grub_util_info ("opening the core image `%s'", core_path);
fp = fopen (core_path, "rb");
fp = grub_util_fopen (core_path, "rb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), core_path,
strerror (errno));
@ -893,7 +893,7 @@ unable_to_embed:
/* Write the first two sectors of the core image onto the disk. */
grub_util_info ("opening the core image `%s'", core_path);
fp = fopen (core_path, "r+b");
fp = grub_util_fopen (core_path, "r+b");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), core_path,
strerror (errno));

View file

@ -101,7 +101,7 @@ grub_util_read_image (const char *path)
size = grub_util_get_image_size (path);
img = (char *) xmalloc (size);
fp = fopen (path, "rb");
fp = grub_util_fopen (path, "rb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), path,
strerror (errno));
@ -125,7 +125,7 @@ grub_util_load_image (const char *path, char *buf)
size = grub_util_get_image_size (path);
fp = fopen (path, "rb");
fp = grub_util_fopen (path, "rb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), path,
strerror (errno));

View file

@ -241,7 +241,7 @@ grub_util_resolve_dependencies (const char *prefix,
struct grub_util_path_list *path_list = 0;
path = grub_util_get_path (prefix, dep_list_file);
fp = fopen (path, "r");
fp = grub_util_fopen (path, "r");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));