]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Add a wrapper for fopen. On unix-like systems just pass-through. On
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 13 Oct 2013 18:36:28 +0000 (20:36 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 13 Oct 2013 18:36:28 +0000 (20:36 +0200)
windows use unicode version.

27 files changed:
ChangeLog
grub-core/commands/acpihalt.c
grub-core/kern/emu/hostdisk.c
grub-core/kern/emu/hostfs.c
grub-core/lib/reed_solomon.c
grub-core/osdep/aros/hostdisk.c
grub-core/osdep/linux/getroot.c
grub-core/osdep/unix/getroot.c
grub-core/osdep/unix/hostdisk.c
grub-core/osdep/unix/random.c
grub-core/osdep/windows/hostdisk.c
include/grub/emu/misc.h
util/grub-editenv.c
util/grub-fstest.c
util/grub-glue-efi.c
util/grub-macho2img.c
util/grub-menulst2cfg.c
util/grub-mkfont.c
util/grub-mkimage.c
util/grub-mklayout.c
util/grub-mount.c
util/grub-pe2elf.c
util/grub-render-label.c
util/grub-script-check.c
util/grub-setup.c
util/misc.c
util/resolve.c

index 0b19f15f6d4fa9e8c0ab6a94c71fef2664da159c..ae500e69a2520fe1ae7a6feb87441830c7dea04c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-10-13  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Add a wrapper for fopen. On unix-like systems just pass-through. On
+       windows use unicode version.
+
 2013-10-13  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Move set_program_name and init_nls to host_init. On windows
index a6c8db6593741ebba802245d5921bb3157727313..09421a6c69d2d0cc4d69560aa12adf8f45499c1f 100644 (file)
@@ -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");
index fb7d72edcd5e0f2737be726a0d9ac96787f88753..6097803cd8f6c4f31dda207a2aa260f74468f8b7 100644 (file)
@@ -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));
index 818a29e6cd79d20101e95a2566cbf642e31632ab..3d9cf24b0ed54404838c86ea11879b059f6e9a30 100644 (file)
@@ -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,
index 704ebd3f2559a96ae81b7899779fd9e655acd20e..aecc1e278c27504252cb981968649836bf854cfe 100644 (file)
@@ -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);
 
index 4bf4575ffefb47c7bff04aa7a20145271c10ea35..1724c7e44f4b7d6219906511e5acfb7cc1ce802e 100644 (file)
@@ -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);
+}
index fb0bad7650651bd4d09a5fac6f1c521762791fb1..689436855a3696fd6851b2994941f20661d72ebd 100644 (file)
@@ -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 */
 
index 19e6dcf8d677003ce4e4403ea06a8f5e78972135..041e9cc9109df6cb21af49a2e34f70028155416d 100644 (file)
@@ -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;
 
index bb0e49f9c6cd4e086dda9fab8de869ee5c255fb5..81e02aef2726b50559b7901a54032f34df9107d7 100644 (file)
@@ -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
index 2a97fc1aa76eab6855ad9fda94307556b47ba8ac..fa0101b0fe21013a9e4dd0012d76718f7ba4340a 100644 (file)
@@ -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);
index 42b58fbabda69ba160b6ea6e160214ae058f535f..8ebde1a6dc96d80c0001201faa20233cf7d677fe 100644 (file)
@@ -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
index 48cc71c77d0f8a4bf2aaaa85520e15d59fd0987c..004ee5bfb4b963fae4bd43b948472752bdec85c6 100644 (file)
@@ -22,6 +22,8 @@
 #include <config.h>
 #include <stdarg.h>
 
+#include <stdio.h>
+
 #include <grub/symbol.h>
 #include <grub/types.h>
 
@@ -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 */
index 7da3fd4a9ddb3d39da624def1544f94db33d7a0c..87428c8d7c992c7c2f9293b710f9dcb084f64acb 100644 (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));
index e6fe3c84f167a80acf1bc82edf93db2605e53b2f..db5da5f447472b3c5825356e7a747e9ad91fa4d2 100644 (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);
index edc4946b85cd3c1062302a7e895b9c9d2614ce23..dcd2808aa167770ef58428c5bfb4e6e1ce3e128a 100644 (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;
 
index 6dfb5fcbefa109a3ec89d834fee7170a0160048c..d6c8a1f65ba4edcc557c68d17b8385f44a66a305 100644 (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);
index ee9b7811216dd24a260641717e29a4c8e4564c04..a39f8693947302fd6f2f47ea1aaba5655a3cf5c4 100644 (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)
index 6532a79b7a68e4f69acfbe2cc78fbcd47b39b7b4..e1f15528236cb92e4567a7654e1b08fd23e83df3 100644 (file)
 #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));
index b606bad760002f1e02a0f839914a17bc2f6b7c93..8819323a27b605cf3f5c81d0093289b23b61e1a9 100644 (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));
index 8f8f3a8cb935587f4e914ffc80b18a969eb4da1a..94d1fa553bd980856be0b0766eef680678936b4f 100644 (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;
 
index f13bc0c0ccd6bc941943016dfd5c3aaa25f8fb6c..a044aa128f6ffe8c69b0dc317560a776a9b85307 100644 (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);
index 57ca47c0df192eaca1a707b2f79f22af04d36129..44189c12a7479a458de02cd0144e6f3c6b1518f3 100644 (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);
 
index c809a981d3baef4e48984d39cf2187367d29aea3..27a1c66f00c9004d0c273aff2011aaae06d9c4a7 100644 (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)
index 9372bdd0f6d95b87a2be8742619e6871bb946c9c..2111efa5a2b1ae11fe0fe908b45aee1bf9bbca61 100644 (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);
index 65d4fb8996267d81c4602cb3af3a108997d50938..8f501bbece45965dbd84b81ebc03a8be3122fd1f 100644 (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));
index af8ad5084fa5fb30d58c97fa220ffa1abe744d50..e6bba751bd2d394faac2bf6b553371b423418929 100644 (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));
index 1af24e6f59fb20abc4473f8c0f1057b395de1be3..002bfbd720b642b03f382bd6e056adc547ebb57a 100644 (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));