+/* Dump database into output_file_name if it's non-NULL, stdout
+ * otherwise.
+ */
+int
+notmuch_database_dump (notmuch_database_t *notmuch,
+ const char *output_file_name,
+ const char *query_str, dump_format_t output_format)
+{
+ FILE *output = stdout;
+ int ret;
+
+ if (output_file_name) {
+ output = fopen (output_file_name, "w");
+ if (output == NULL) {
+ fprintf (stderr, "Error opening %s for writing: %s\n",
+ output_file_name, strerror (errno));
+ return EXIT_FAILURE;
+ }
+ }
+
+ ret = database_dump_file (notmuch, output, query_str, output_format);
+
+ if (output != stdout)
+ fclose (output);
+
+ return ret;
+}
+