Add a wrapper for fopen. On unix-like systems just pass-through. On
windows use unicode version.
This commit is contained in:
parent
ae5540d3d4
commit
bb338aaf24
27 changed files with 97 additions and 41 deletions
|
@ -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");
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue