Skip to content

Commit 15e9fda

Browse files
committed
fix of the zlib error handling
1 parent afd7987 commit 15e9fda

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/bin/pg_dump/compress_io.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ cfread(void *ptr, int size, cfp *fp)
593593
ret = gzread(fp->compressedfp, ptr, size);
594594
if (ret != size && !gzeof(fp->compressedfp))
595595
exit_horribly(modulename,
596-
"could not read from input file: %s\n", strerror(errno));
596+
"could not read from input file: %s\n", get_gz_error(fp->compressedfp));
597597
}
598598
else
599599
#endif
@@ -629,7 +629,7 @@ cfgetc(cfp *fp)
629629
{
630630
if (!gzeof(fp->compressedfp))
631631
exit_horribly(modulename,
632-
"could not read from input file: %s\n", strerror(errno));
632+
"could not read from input file: %s\n", get_gz_error(fp->compressedfp));
633633
else
634634
exit_horribly(modulename,
635635
"could not read from input file: end of file\n");
@@ -710,4 +710,16 @@ hasSuffix(const char *filename, const char *suffix)
710710
suffixlen) == 0;
711711
}
712712

713+
const char *
714+
get_gz_error(gzFile gzf)
715+
{
716+
int errnum;
717+
const char *errmsg;
718+
719+
errmsg = gzerror(gzf, &errnum);
720+
if (errnum == Z_ERRNO)
721+
return strerror(errno);
722+
else
723+
return errmsg;
724+
}
713725
#endif

src/bin/pg_dump/compress_io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern void ReadDataFromArchive(ArchiveHandle *AH, int compression,
5252
extern void WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
5353
const void *data, size_t dLen);
5454
extern void EndCompressor(ArchiveHandle *AH, CompressorState *cs);
55+
extern const char * get_gz_error(gzFile gzf);
5556

5657

5758
typedef struct cfp cfp;

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "pgtar.h"
3636
#include "common/file_utils.h"
3737
#include "fe_utils/string_utils.h"
38+
#include "compress_io.h"
3839

3940
#include <sys/stat.h>
4041
#include <ctype.h>
@@ -556,7 +557,7 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
556557
res = GZREAD(&((char *) buf)[used], 1, len, th->zFH);
557558
if (res != len && !GZEOF(th->zFH))
558559
exit_horribly(modulename,
559-
"could not read from input file: %s\n", strerror(errno));
560+
"could not read from input file: %s\n", get_gz_error(th->zFH));
560561
}
561562
else
562563
{

0 commit comments

Comments
 (0)