zdump/zg: Save errno in _zg_err_errno()

_zg_err_errno() should save the current errno value before calling any
libc functions because they could change it. Failing to do so, may result
in _zg_err_errno() displaying an incorrect error message.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Alexander Egorenkov
2021-11-24 06:19:33 +01:00
committed by Jan Höppner
parent 81013f0c70
commit 2238eb820f

View File

@@ -19,10 +19,12 @@ static inline void _zg_err(const char *fmt, va_list ap)
static inline void _zg_err_errno(const char *fmt, va_list ap)
{
const int errno_backup = errno;
fflush(stdout);
fprintf(stderr, "%s: ", "zgetdump");
vfprintf(stderr, fmt, ap);
fprintf(stderr, " (%s)", strerror(errno));
fprintf(stderr, " (%s)", strerror(errno_backup));
fprintf(stderr, "\n");
}