Move file loading functions to grub-emu.
So that we can use it in grub-emu as well as utils.
This commit is contained in:
parent
f2b54835f2
commit
3f430a0126
2 changed files with 48 additions and 48 deletions
|
@ -149,3 +149,51 @@ grub_get_time_ms (void)
|
|||
|
||||
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
size_t
|
||||
grub_util_get_image_size (const char *path)
|
||||
{
|
||||
FILE *f;
|
||||
size_t ret;
|
||||
off_t sz;
|
||||
|
||||
f = grub_util_fopen (path, "rb");
|
||||
|
||||
if (!f)
|
||||
grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
|
||||
|
||||
fseeko (f, 0, SEEK_END);
|
||||
|
||||
sz = ftello (f);
|
||||
if (sz < 0)
|
||||
grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
|
||||
if (sz != (size_t) sz)
|
||||
grub_util_error (_("file `%s' is too big"), path);
|
||||
ret = (size_t) sz;
|
||||
|
||||
fclose (f);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_load_image (const char *path, char *buf)
|
||||
{
|
||||
FILE *fp;
|
||||
size_t size;
|
||||
|
||||
grub_util_info ("reading %s", path);
|
||||
|
||||
size = grub_util_get_image_size (path);
|
||||
|
||||
fp = grub_util_fopen (path, "rb");
|
||||
if (! fp)
|
||||
grub_util_error (_("cannot open `%s': %s"), path,
|
||||
strerror (errno));
|
||||
|
||||
if (fread (buf, 1, size, fp) != size)
|
||||
grub_util_error (_("cannot read `%s': %s"), path,
|
||||
strerror (errno));
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
|
|
48
util/misc.c
48
util/misc.c
|
@ -74,32 +74,6 @@ grub_util_get_path (const char *dir, const char *file)
|
|||
return path;
|
||||
}
|
||||
|
||||
size_t
|
||||
grub_util_get_image_size (const char *path)
|
||||
{
|
||||
FILE *f;
|
||||
size_t ret;
|
||||
off_t sz;
|
||||
|
||||
f = grub_util_fopen (path, "rb");
|
||||
|
||||
if (!f)
|
||||
grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
|
||||
|
||||
fseeko (f, 0, SEEK_END);
|
||||
|
||||
sz = ftello (f);
|
||||
if (sz < 0)
|
||||
grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
|
||||
if (sz != (size_t) sz)
|
||||
grub_util_error (_("file `%s' is too big"), path);
|
||||
ret = (size_t) sz;
|
||||
|
||||
fclose (f);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_util_read_image (const char *path)
|
||||
{
|
||||
|
@ -126,28 +100,6 @@ grub_util_read_image (const char *path)
|
|||
return img;
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_load_image (const char *path, char *buf)
|
||||
{
|
||||
FILE *fp;
|
||||
size_t size;
|
||||
|
||||
grub_util_info ("reading %s", path);
|
||||
|
||||
size = grub_util_get_image_size (path);
|
||||
|
||||
fp = grub_util_fopen (path, "rb");
|
||||
if (! fp)
|
||||
grub_util_error (_("cannot open `%s': %s"), path,
|
||||
strerror (errno));
|
||||
|
||||
if (fread (buf, 1, size, fp) != size)
|
||||
grub_util_error (_("cannot read `%s': %s"), path,
|
||||
strerror (errno));
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_write_image_at (const void *img, size_t size, off_t offset, FILE *out,
|
||||
const char *name)
|
||||
|
|
Loading…
Reference in a new issue