]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Move file loading functions to grub-emu.
authorVladimir Serbinenko <phcoder@gmail.com>
Tue, 5 Jan 2016 11:49:12 +0000 (12:49 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Tue, 5 Jan 2016 20:10:27 +0000 (21:10 +0100)
So that we can use it in grub-emu as well as utils.

grub-core/kern/emu/misc.c
util/misc.c

index bb606da28039b7af41a6dca46b44fd73959f6af1..06985013d846c1d2a691cdae0b5084c8e92b8146 100644 (file)
@@ -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);
+}
index b8ec69108cbc91d44ac75a44625879f43dfd925b..d545212d90ec4b69a1150ede1f8a033a8812d019 100644 (file)
@@ -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)