diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c index bb606da28..06985013d 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -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); +} diff --git a/util/misc.c b/util/misc.c index b8ec69108..d545212d9 100644 --- a/util/misc.c +++ b/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)