diff --git a/ChangeLog b/ChangeLog index 0b19f15f6..ae500e69a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-10-13 Vladimir Serbinenko + + Add a wrapper for fopen. On unix-like systems just pass-through. On + windows use unicode version. + 2013-10-13 Vladimir Serbinenko Move set_program_name and init_nls to host_init. On windows diff --git a/grub-core/commands/acpihalt.c b/grub-core/commands/acpihalt.c index a6c8db659..09421a6c6 100644 --- a/grub-core/commands/acpihalt.c +++ b/grub-core/commands/acpihalt.c @@ -295,7 +295,7 @@ main (int argc, char **argv) unsigned char *buf; if (argc < 2) printf ("Usage: %s FILE\n", argv[0]); - f = fopen (argv[1], "rb"); + f = grub_util_fopen (argv[1], "rb"); if (!f) { printf ("Couldn't open file\n"); diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index fb7d72edc..6097803cd 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -435,7 +435,7 @@ read_device_map (const char *dev_map) return; } - fp = fopen (dev_map, "r"); + fp = grub_util_fopen (dev_map, "r"); if (! fp) { grub_util_info (_("cannot open `%s': %s"), dev_map, strerror (errno)); diff --git a/grub-core/kern/emu/hostfs.c b/grub-core/kern/emu/hostfs.c index 818a29e6c..3d9cf24b0 100644 --- a/grub-core/kern/emu/hostfs.c +++ b/grub-core/kern/emu/hostfs.c @@ -109,7 +109,7 @@ grub_hostfs_open (struct grub_file *file, const char *name) FILE *f; struct grub_hostfs_data *data; - f = fopen (name, "rb"); + f = grub_util_fopen (name, "rb"); if (! f) return grub_error (GRUB_ERR_BAD_FILENAME, N_("can't open `%s': %s"), name, diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 704ebd3f2..aecc1e278 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -425,7 +425,7 @@ main (int argc, char **argv) #endif #ifndef STANDALONE - in = fopen ("tst.bin", "rb"); + in = grub_util_fopen ("tst.bin", "rb"); if (!in) return 1; fseek (in, 0, SEEK_END); @@ -438,11 +438,11 @@ main (int argc, char **argv) grub_reed_solomon_add_redundancy (buf, s, rs); - out = fopen ("tst_rs.bin", "wb"); + out = grub_util_fopen ("tst_rs.bin", "wb"); fwrite (buf, 1, s + rs, out); fclose (out); #else - out = fopen ("tst_rs.bin", "rb"); + out = grub_util_fopen ("tst_rs.bin", "rb"); fseek (out, 0, SEEK_END); s = ftell (out); fseek (out, 0, SEEK_SET); @@ -457,12 +457,12 @@ main (int argc, char **argv) grub_memset (buf + 512 * 15, 0, 512); #endif - out = fopen ("tst_dam.bin", "wb"); + out = grub_util_fopen ("tst_dam.bin", "wb"); fwrite (buf, 1, s + rs, out); fclose (out); grub_reed_solomon_recover (buf, s, rs); - out = fopen ("tst_rec.bin", "wb"); + out = grub_util_fopen ("tst_rec.bin", "wb"); fwrite (buf, 1, s, out); fclose (out); diff --git a/grub-core/osdep/aros/hostdisk.c b/grub-core/osdep/aros/hostdisk.c index 4bf4575ff..1724c7e44 100644 --- a/grub-core/osdep/aros/hostdisk.c +++ b/grub-core/osdep/aros/hostdisk.c @@ -499,3 +499,9 @@ grub_util_fd_strerror (void) return buf + 1; return buf; } + +FILE * +grub_util_fopen (const char *path, const char *mode) +{ + return fopen (path, mode); +} diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c index fb0bad765..689436855 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -239,7 +239,7 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) if (relroot) *relroot = NULL; - fp = fopen ("/proc/self/mountinfo", "r"); + fp = grub_util_fopen ("/proc/self/mountinfo", "r"); if (! fp) return NULL; /* fall through to other methods */ diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c index 19e6dcf8d..041e9cc91 100644 --- a/grub-core/osdep/unix/getroot.c +++ b/grub-core/osdep/unix/getroot.c @@ -721,7 +721,7 @@ grub_find_zpool_from_dir (const char *dir, char **poolname, char **poolfs) if (stat (dir, &st) != 0) return; - FILE *mnttab = fopen ("/etc/mnttab", "r"); + FILE *mnttab = grub_util_fopen ("/etc/mnttab", "r"); if (! mnttab) return; diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdisk.c index bb0e49f9c..81e02aef2 100644 --- a/grub-core/osdep/unix/hostdisk.c +++ b/grub-core/osdep/unix/hostdisk.c @@ -211,4 +211,10 @@ canonicalize_file_name (const char *path) #endif } +FILE * +grub_util_fopen (const char *path, const char *mode) +{ + return fopen (path, mode); +} + #endif diff --git a/grub-core/osdep/unix/random.c b/grub-core/osdep/unix/random.c index 2a97fc1aa..fa0101b0f 100644 --- a/grub-core/osdep/unix/random.c +++ b/grub-core/osdep/unix/random.c @@ -36,7 +36,7 @@ grub_get_random (void *out, grub_size_t len) FILE *f; size_t rd; - f = fopen ("/dev/urandom", "rb"); + f = grub_util_fopen ("/dev/urandom", "rb"); if (!f) return 1; rd = fread (out, 1, len, f); diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c index 42b58fbab..8ebde1a6d 100644 --- a/grub-core/osdep/windows/hostdisk.c +++ b/grub-core/osdep/windows/hostdisk.c @@ -291,9 +291,35 @@ canonicalize_file_name (const char *path) #ifdef __MINGW32__ +FILE * +grub_util_fopen (const char *path, const char *mode) +{ + LPTSTR tpath; + FILE *ret; + tpath = grub_util_get_windows_path (path); +#if SIZEOF_TCHAR == 1 + ret = fopen (tpath, tmode); +#else + LPTSTR tmode; + tmode = grub_util_utf8_to_tchar (mode); + ret = _wfopen (tpath, tmode); + free (tmode); +#endif + free (tpath); + return ret; +} + int fsync (int fno __attribute__ ((unused))) { return 0; } +#else + +FILE * +grub_util_fopen (const char *path, const char *mode) +{ + return fopen (path, mode); +} + #endif diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h index 48cc71c77..004ee5bfb 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h @@ -22,6 +22,8 @@ #include #include +#include + #include #include @@ -54,4 +56,11 @@ extern char * canonicalize_file_name (const char *path); int grub_device_mapper_supported (void); #endif +#ifdef GRUB_BUILD +#define grub_util_fopen fopen +#else +FILE * +grub_util_fopen (const char *path, const char *mode); +#endif + #endif /* GRUB_EMU_MISC_H */ diff --git a/util/grub-editenv.c b/util/grub-editenv.c index 7da3fd4a9..87428c8d7 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -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)); diff --git a/util/grub-fstest.c b/util/grub-fstest.c index e6fe3c84f..db5da5f44 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -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); diff --git a/util/grub-glue-efi.c b/util/grub-glue-efi.c index edc4946b8..dcd2808aa 100644 --- a/util/grub-glue-efi.c +++ b/util/grub-glue-efi.c @@ -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; diff --git a/util/grub-macho2img.c b/util/grub-macho2img.c index 6dfb5fcbe..d6c8a1f65 100644 --- a/util/grub-macho2img.c +++ b/util/grub-macho2img.c @@ -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); diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c index ee9b78112..a39f86939 100644 --- a/util/grub-menulst2cfg.c +++ b/util/grub-menulst2cfg.c @@ -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) diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 6532a79b7..e1f155282 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -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)); diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index b606bad76..8819323a2 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -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)); diff --git a/util/grub-mklayout.c b/util/grub-mklayout.c index 8f8f3a8cb..94d1fa553 100644 --- a/util/grub-mklayout.c +++ b/util/grub-mklayout.c @@ -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; diff --git a/util/grub-mount.c b/util/grub-mount.c index f13bc0c0c..a044aa128 100644 --- a/util/grub-mount.c +++ b/util/grub-mount.c @@ -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); diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c index 57ca47c0d..44189c12a 100644 --- a/util/grub-pe2elf.c +++ b/util/grub-pe2elf.c @@ -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); diff --git a/util/grub-render-label.c b/util/grub-render-label.c index c809a981d..27a1c66f0 100644 --- a/util/grub-render-label.c +++ b/util/grub-render-label.c @@ -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) diff --git a/util/grub-script-check.c b/util/grub-script-check.c index 9372bdd0f..2111efa5a 100644 --- a/util/grub-script-check.c +++ b/util/grub-script-check.c @@ -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); diff --git a/util/grub-setup.c b/util/grub-setup.c index 65d4fb899..8f501bbec 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -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)); diff --git a/util/misc.c b/util/misc.c index af8ad5084..e6bba751b 100644 --- a/util/misc.c +++ b/util/misc.c @@ -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)); diff --git a/util/resolve.c b/util/resolve.c index 1af24e6f5..002bfbd72 100644 --- a/util/resolve.c +++ b/util/resolve.c @@ -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));