+ if (fread (buf, 1, 4, ifp) != 4)
+ return 1;
+ *valp = bfd_get_32 (core_bfd, buf);
+ return 0;
+}
+
+#ifdef BFD_HOST_U_64_BIT
+static int
+gmon_io_read_64 (FILE *ifp, BFD_HOST_U_64_BIT *valp)
+{
+ char buf[8];
+
+ if (fread (buf, 1, 8, ifp) != 8)
+ return 1;
+ *valp = bfd_get_64 (core_bfd, buf);
+ return 0;
+}
+#endif
+
+int
+gmon_io_read_vma (FILE *ifp, bfd_vma *valp)
+{
+ unsigned int val32;
+#ifdef BFD_HOST_U_64_BIT
+ BFD_HOST_U_64_BIT val64;
+#endif
+
+ switch (gmon_get_ptr_size ())
+ {
+ case ptr_32bit:
+ if (gmon_io_read_32 (ifp, &val32))
+ return 1;
+ if (gmon_get_ptr_signedness () == ptr_signed)
+ *valp = (int) val32;
+ else
+ *valp = val32;
+ break;
+
+#ifdef BFD_HOST_U_64_BIT
+ case ptr_64bit:
+ if (gmon_io_read_64 (ifp, &val64))
+ return 1;
+#ifdef BFD_HOST_64_BIT
+ if (gmon_get_ptr_signedness () == ptr_signed)
+ *valp = (BFD_HOST_64_BIT) val64;
+ else
+#endif
+ *valp = val64;
+ break;
+#endif
+ }
+ return 0;
+}
+
+int
+gmon_io_read (FILE *ifp, char *buf, size_t n)
+{
+ if (fread (buf, 1, n, ifp) != n)
+ return 1;
+ return 0;
+}
+
+int
+gmon_io_write_32 (FILE *ofp, unsigned int val)
+{
+ char buf[4];
+
+ bfd_put_32 (core_bfd, (bfd_vma) val, buf);
+ if (fwrite (buf, 1, 4, ofp) != 4)
+ return 1;
+ return 0;
+}
+
+#ifdef BFD_HOST_U_64_BIT
+static int
+gmon_io_write_64 (FILE *ofp, BFD_HOST_U_64_BIT val)
+{
+ char buf[8];
+
+ bfd_put_64 (core_bfd, (bfd_vma) val, buf);
+ if (fwrite (buf, 1, 8, ofp) != 8)
+ return 1;
+ return 0;
+}
+#endif
+
+int
+gmon_io_write_vma (FILE *ofp, bfd_vma val)
+{
+
+ switch (gmon_get_ptr_size ())
+ {
+ case ptr_32bit:
+ if (gmon_io_write_32 (ofp, (unsigned int) val))
+ return 1;
+ break;
+
+#ifdef BFD_HOST_U_64_BIT
+ case ptr_64bit:
+ if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) val))
+ return 1;
+ break;
+#endif
+ }
+ return 0;
+}
+
+int
+gmon_io_write_8 (FILE *ofp, unsigned int val)
+{
+ char buf[1];
+
+ bfd_put_8 (core_bfd, val, buf);
+ if (fwrite (buf, 1, 1, ofp) != 1)
+ return 1;
+ return 0;
+}
+
+int
+gmon_io_write (FILE *ofp, char *buf, size_t n)
+{
+ if (fwrite (buf, 1, n, ofp) != n)
+ return 1;
+ return 0;
+}
+
+static int
+gmon_read_raw_arc (FILE *ifp, bfd_vma *fpc, bfd_vma *spc, unsigned long *cnt)