error.c 991 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*******************************************************************************
 * Copyright 2019 UChicago Argonne, LLC.
 * (c.f. AUTHORS, LICENSE)
 *
 * This file is part of the AML project.
 * For more info, see https://xgitlab.cels.anl.gov/argo/aml
 *
 * SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/

#include "aml.h"
12 13
#include <stdio.h>

14 15 16 17 18 19
static const char * const aml_error_strings[] = {
	[AML_SUCCESS]	= "Success",
	[AML_FAILURE]	= "Generic error",
	[AML_ENOMEM]	= "Not enough memory",
	[AML_EINVAL]	= "Invalid argument",
	[AML_EDOM]	= "Value out of bound",
20
	[AML_EBUSY]	= "Underlying resource is not available for operation",
21 22
	[AML_ENOTSUP]	= "Operation not supported",
};
23

24
const char *aml_strerror(const int err)
25
{
26
	if (err < 0 || err >= AML_ERROR_MAX)
27
		return "Unknown error";
28
	return aml_error_strings[err];
29 30
}

31
void aml_perror(const char *msg)
32 33 34
{
	fprintf(stderr, "%s:%s\n", msg, aml_strerror(aml_errno));
}