windows use unicode version.
+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
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");
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));
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,
#endif
#ifndef STANDALONE
- in = fopen ("tst.bin", "rb");
+ in = grub_util_fopen ("tst.bin", "rb");
if (!in)
return 1;
fseek (in, 0, SEEK_END);
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);
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);
return buf + 1;
return buf;
}
+
+FILE *
+grub_util_fopen (const char *path, const char *mode)
+{
+ return fopen (path, mode);
+}
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 */
if (stat (dir, &st) != 0)
return;
- FILE *mnttab = fopen ("/etc/mnttab", "r");
+ FILE *mnttab = grub_util_fopen ("/etc/mnttab", "r");
if (! mnttab)
return;
#endif
}
+FILE *
+grub_util_fopen (const char *path, const char *mode)
+{
+ return fopen (path, mode);
+}
+
#endif
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);
#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
#include <config.h>
#include <stdarg.h>
+#include <stdio.h>
+
#include <grub/symbol.h>
#include <grub/types.h>
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 */
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));
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));
{
FILE *fp;
- fp = fopen (name, "wb");
+ fp = grub_util_fopen (name, "wb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), name,
strerror (errno));
.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,
return;
}
- ff = fopen (dest, "rb");
+ ff = grub_util_fopen (dest, "rb");
if (ff == NULL)
{
grub_util_error (_("OS file %s open error: %s"), dest,
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);
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;
"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);
if (argc >= 2)
{
- in = fopen (argv[1], "r");
+ in = grub_util_fopen (argv[1], "r");
if (!in)
{
fprintf (stderr, _("cannot open `%s': %s"),
if (argc >= 3)
{
- out = fopen (argv[2], "w");
+ out = grub_util_fopen (argv[2], "w");
if (!out)
{
if (in != stdin)
#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
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));
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));
}
if (arguments.input)
- in = fopen (arguments.input, "r");
+ in = grub_util_fopen (arguments.input, "r");
else
in = stdin;
strerror (errno));
if (arguments.output)
- out = fopen (arguments.output, "wb");
+ out = grub_util_fopen (arguments.output, "wb");
else
out = stdout;
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);
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);
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,
}
if (arguments.output)
- out = fopen (arguments.output, "wb");
+ out = grub_util_fopen (arguments.output, "wb");
else
out = stdout;
if (!out)
}
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);
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);
/* 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));
/* 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));
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));
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));
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));