+/* Displays MSG as an warning for the current position in
+ portable file reader R. */
+static void
+warning (struct pfm_reader *r, const char *msg, ...)
+{
+ struct msg m;
+ struct string text;
+ va_list args;
+
+ ds_init_empty (&text);
+ ds_put_format (&text, _("reading portable file %s at offset 0x%lx: "),
+ fh_get_file_name (r->fh), ftell (r->file));
+ va_start (args, msg);
+ ds_put_vformat (&text, msg, args);
+ va_end (args);
+
+ m.category = MSG_GENERAL;
+ m.severity = MSG_WARNING;
+ m.where.file_name = NULL;
+ m.where.line_number = 0;
+ m.text = ds_cstr (&text);
+
+ msg_emit (&m);
+}
+
+/* Close and destroy R.
+ Returns false if an error was detected on R, true otherwise. */
+static bool
+close_reader (struct pfm_reader *r)
+{
+ bool ok;
+ if (r == NULL)
+ return true;
+
+ if (r->file)
+ {
+ if (fn_close (fh_get_file_name (r->fh), r->file) == EOF)
+ {
+ msg (ME, _("Error closing portable file \"%s\": %s."),
+ fh_get_file_name (r->fh), strerror (errno));
+ r->ok = false;
+ }
+ r->file = NULL;
+ }
+
+ fh_unlock (r->lock);
+ fh_unref (r->fh);
+
+ ok = r->ok;
+ pool_destroy (r->pool);
+
+ return ok;
+}
+