Files
s390-tools/zipl/src/error.c
Michael Holzheu b627b8d8e1 Initial s390-tools-2.0.0 import
This commit is based on the s390-tools-1.39.0 version.

Changes on top of s390-tools-1.39.0:

 - Add MIT license to all source files
 - Add LICENSE file
 - Transform REAMDE to README.md (markdown)
 - Add AUTHORS.md file
 - Add CONTRIBUTING.md file
 - Move changelog from README to CHANGELOG.md file

Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
2017-08-21 10:55:40 +02:00

85 lines
1.8 KiB
C

/*
* zipl - zSeries Initial Program Loader tool
*
* Functions to handle error messages
*
* Copyright IBM Corp. 2001, 2017
*
* 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 <stdio.h>
#include "error.h"
#define ERROR_STRING_SIZE 1024
static char error_reason_string[ERROR_STRING_SIZE];
static char error_text_string[ERROR_STRING_SIZE];
static int error_is_reason = 0;
static int error_is_text = 0;
/* Specify the actual reason why an operation failed by providing a formatted
* text string FMT and a variable amount of extra arguments. */
void
error_reason(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
vsnprintf(error_reason_string, ERROR_STRING_SIZE, fmt, args);
va_end(args);
error_is_reason = 1;
}
/* Specify the (higher level) tool operation failure by providing a formatted
* text string FMT and a variable amount of extra arguments. */
void
error_text(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
vsnprintf(error_text_string, ERROR_STRING_SIZE, fmt, args);
va_end(args);
error_is_text = 1;
}
/* Clear a previously specified error_reason() message. */
void
error_clear_reason(void)
{
error_is_reason = 0;
}
/* Clear a previously specified error_text() message. */
void
error_clear_text(void)
{
error_is_text = 0;
}
/* Print out the error reason and text message to stderr. */
void
error_print(void)
{
if (error_is_text && error_is_reason) {
fprintf(stderr, "Error: %s: %s\n", error_text_string,
error_reason_string);
} else if (error_is_text)
fprintf(stderr, "Error: %s\n", error_text_string);
else if (error_is_reason)
fprintf(stderr, "Error: %s\n", error_reason_string);
else
fprintf(stderr, "Error: An unspecified error occurred\n");
}