From 3de87e733ca7041bad06f8e42b8917d040d61355 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyoga.ntt@gmail.com>
Date: Wed, 21 Oct 2020 14:10:04 +0900
Subject: [PATCH 2/2] Use correct function to get error message in gzread and
 gzgetc.

cfread() had the equivalent code with get_crp_error(), and cfgetc()
used strerror() to get error message of gzgetc(). Use get_cfp_error()
at the two places.
---
 src/bin/pg_dump/compress_io.c         | 10 ++--------
 src/bin/pg_dump/pg_backup_directory.c |  3 ++-
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_dump/compress_io.c b/src/bin/pg_dump/compress_io.c
index 28d45fd299..686472e045 100644
--- a/src/bin/pg_dump/compress_io.c
+++ b/src/bin/pg_dump/compress_io.c
@@ -577,13 +577,7 @@ cfread(void *ptr, int size, cfp *fp)
 	{
 		ret = gzread(fp->compressedfp, ptr, size);
 		if (ret != size && !gzeof(fp->compressedfp))
-		{
-			int			errnum;
-			const char *errmsg = gzerror(fp->compressedfp, &errnum);
-
-			fatal("could not read from input file: %s",
-				  errnum == Z_ERRNO ? strerror(errno) : errmsg);
-		}
+			fatal("could not read from input file: %s", get_cfp_error(fp));
 	}
 	else
 #endif
@@ -618,7 +612,7 @@ cfgetc(cfp *fp)
 		if (ret == EOF)
 		{
 			if (!gzeof(fp->compressedfp))
-				fatal("could not read from input file: %s", strerror(errno));
+				fatal("could not read from input file: %s", get_cfp_error(fp));
 			else
 				fatal("could not read from input file: end of file");
 		}
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
index 4b1cf4a5a3..56e0c27e29 100644
--- a/src/bin/pg_dump/pg_backup_directory.c
+++ b/src/bin/pg_dump/pg_backup_directory.c
@@ -698,7 +698,8 @@ _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
 	/* register the blob in blobs.toc */
 	len = snprintf(buf, sizeof(buf), "%u blob_%u.dat\n", oid, oid);
 	if (cfwrite(buf, len, ctx->blobsTocFH) != len)
-		fatal("could not write to blobs TOC file");
+		fatal("could not write to blobs TOC file: %s",
+			  get_cfp_error(ctx->blobsTocFH));
 }
 
 /*
-- 
2.18.4

