$OpenBSD: patch-notmuch-dump_c,v 1.2 2020/08/13 18:21:19 sthen Exp $

replace zlib macros by stdio equivalent because our zlib does not have
"transparent" (no compression) mode so we disable compression
altogether.

Index: notmuch-dump.c
--- notmuch-dump.c.orig
+++ notmuch-dump.c
@@ -24,7 +24,7 @@
 #include "zlib-extra.h"
 
 static int
-database_dump_config (notmuch_database_t *notmuch, gzFile output)
+database_dump_config (notmuch_database_t *notmuch, FILE *output)
 {
     notmuch_config_list_t *list;
     int ret = EXIT_FAILURE;
@@ -69,7 +69,7 @@ database_dump_config (notmuch_database_t *notmuch, gzF
 }
 
 static void
-print_dump_header (gzFile output, int output_format, int include)
+print_dump_header (FILE *output, int output_format, int include)
 {
     const char *sep = "";
 
@@ -94,7 +94,7 @@ print_dump_header (gzFile output, int output_format, i
 static int
 dump_properties_message (void *ctx,
 			 notmuch_message_t *message,
-			 gzFile output,
+			 FILE *output,
 			 char **buffer_p, size_t *size_p)
 {
     const char *message_id;
@@ -147,7 +147,7 @@ dump_properties_message (void *ctx,
 static int
 dump_tags_message (void *ctx,
 		   notmuch_message_t *message, int output_format,
-		   gzFile output,
+		   FILE *output,
 		   char **buffer_p, size_t *size_p)
 {
     int first = 1;
@@ -208,7 +208,7 @@ dump_tags_message (void *ctx,
 }
 
 static int
-database_dump_file (notmuch_database_t *notmuch, gzFile output,
+database_dump_file (notmuch_database_t *notmuch, FILE *output,
 		    const char *query_str, int output_format, int include)
 {
     notmuch_query_t *query;
@@ -281,8 +281,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
 		       dump_include_t include,
 		       bool gzip_output)
 {
-    gzFile output = NULL;
-    const char *mode = gzip_output ? "w9" : "wT";
+    FILE *output = NULL;
     const char *name_for_error = output_file_name ? output_file_name : "stdout";
 
     char *tempname = NULL;
@@ -302,10 +301,10 @@ notmuch_database_dump (notmuch_database_t *notmuch,
 	goto DONE;
     }
 
-    output = gzdopen (outfd, mode);
+    output = fdopen (outfd, "w");
 
     if (output == NULL) {
-	fprintf (stderr, "Error opening %s for (gzip) writing: %s\n",
+	fprintf (stderr, "Error opening %s for writing: %s\n",
 		 name_for_error, strerror (errno));
 	if (close (outfd))
 	    fprintf (stderr, "Error closing %s during shutdown: %s\n",
@@ -316,9 +315,9 @@ notmuch_database_dump (notmuch_database_t *notmuch,
     ret = database_dump_file (notmuch, output, query_str, output_format, include);
     if (ret) goto DONE;
 
-    ret = gzflush (output, Z_FINISH);
+    ret = fflush (output);
     if (ret) {
-	fprintf (stderr, "Error flushing output: %s\n", gzerror_str (output));
+	fprintf (stderr, "Error flushing output: %s\n", strerror (errno));
 	goto DONE;
     }
 
@@ -331,10 +330,10 @@ notmuch_database_dump (notmuch_database_t *notmuch,
 	}
     }
 
-    ret = gzclose_w (output);
+    ret = fclose (output);
     if (ret) {
 	fprintf (stderr, "Error closing %s: %s\n", name_for_error,
-		 gzerror_str (output));
+		 strerror (errno));
 	ret = EXIT_FAILURE;
 	output = NULL;
 	goto DONE;
@@ -352,7 +351,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
     }
   DONE:
     if (ret != EXIT_SUCCESS && output)
-	(void) gzclose_w (output);
+	(void) fclose (output);
 
     if (ret != EXIT_SUCCESS && output_file_name)
 	(void) unlink (tempname);
@@ -390,7 +389,6 @@ notmuch_dump_command (notmuch_config_t *config, int ar
 				      { "properties", DUMP_INCLUDE_PROPERTIES },
 				      { "tags", DUMP_INCLUDE_TAGS } } },
 	{ .opt_string = &output_file_name, .name = "output" },
-	{ .opt_bool = &gzip_output, .name = "gzip" },
 	{ .opt_inherit = notmuch_shared_options },
 	{ }
     };
