]> git.notmuchmail.org Git - notmuch/commitdiff
status: add print_status_gzbytes
authorDavid Bremner <david@tethera.net>
Sun, 12 Apr 2020 23:17:20 +0000 (20:17 -0300)
committerDavid Bremner <david@tethera.net>
Mon, 13 Apr 2020 20:14:50 +0000 (17:14 -0300)
This is in the client code, rather than libnotmuch_util, because it
prints to stderr. Also it in pretends to generate notmuch status
codes.

notmuch-client.h
status.c

index 89e15ba649f7b93f41b3ac729c477c2ec5d70225..467e1d84c6cf4a16febac2e588fe2df7219b8116 100644 (file)
@@ -49,6 +49,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <ctype.h>
+#include <zlib.h>
 
 #include "talloc-extra.h"
 #include "crypto.h"
@@ -469,7 +470,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
                       dump_include_t include,
                       bool gzip_output);
 
-/* If status is non-zero (i.e. error) print appropriate
+/* If status indicates error print appropriate
  * messages to stderr.
  */
 
@@ -491,6 +492,11 @@ print_status_database (const char *loc,
 int
 status_to_exit (notmuch_status_t status);
 
+notmuch_status_t
+print_status_gzbytes (const char *loc,
+                     gzFile file,
+                     int bytes);
+
 #include "command-line-arguments.h"
 
 extern const char *notmuch_requested_db_uuid;
index d0ae47f4d03cb6eb5522df2913f170d77d15e71f..09d82a172ba8315aa5184db0aa6bedfa6651b180 100644 (file)
--- a/status.c
+++ b/status.c
@@ -72,3 +72,17 @@ status_to_exit (notmuch_status_t status)
        return EXIT_FAILURE;
     }
 }
+
+notmuch_status_t
+print_status_gzbytes (const char *loc, gzFile file, int bytes)
+{
+    if (bytes <= 0) {
+       int errnum;
+       const char *errstr = gzerror (file, &errnum);
+       fprintf (stderr, "%s: zlib error %s (%d)\n", loc, errstr, errnum);
+       return NOTMUCH_STATUS_FILE_ERROR;
+    } else {
+       return NOTMUCH_STATUS_SUCCESS;
+    }
+}
+