mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
_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>
73 lines
1.2 KiB
C
73 lines
1.2 KiB
C
/*
|
|
* Copyright IBM Corp. 2001, 2017, 2021
|
|
*
|
|
* s390-tools is free software; you can redistribute it and/or modify
|
|
* it under the terms of the MIT license. See LICENSE for details.
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "lib/util_libc.h"
|
|
#include "zg.h"
|
|
|
|
static inline void _zg_err(const char *fmt, va_list ap)
|
|
{
|
|
fprintf(stderr, "%s: ", "zgetdump");
|
|
vfprintf(stderr, fmt, ap);
|
|
fprintf(stderr, "\n");
|
|
}
|
|
|
|
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_backup));
|
|
fprintf(stderr, "\n");
|
|
}
|
|
|
|
void zg_err(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
_zg_err(fmt, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
void zg_err_exit(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
_zg_err(fmt, ap);
|
|
va_end(ap);
|
|
zg_exit(1);
|
|
}
|
|
|
|
void zg_err_exit_errno(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
_zg_err_errno(fmt, ap);
|
|
va_end(ap);
|
|
zg_exit(1);
|
|
}
|
|
|
|
void zg_abort(const char *fmt, ...)
|
|
{
|
|
char *newfmt;
|
|
va_list ap;
|
|
|
|
newfmt = util_strcat_realloc(util_strdup("Internal Error: "), fmt);
|
|
va_start(ap, fmt);
|
|
_zg_err(newfmt, ap);
|
|
va_end(ap);
|
|
free(newfmt);
|
|
|
|
abort();
|
|
}
|