aboutsummaryrefslogtreecommitdiffstats
path: root/src/zerror.c
blob: e4ed427c3f0ce14796c1d7166f02f2ecd0016333 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* See LICENSE file for copyright and license details. */
#include "internals.h"


#define LIST_ERRORS\
	X(ZERROR_0_POW_0,  "indeterminate form: 0:th power of 0")\
	X(ZERROR_0_DIV_0,  "indeterminate form: 0 divided by 0")\
	X(ZERROR_DIV_0,    "undefined result: division by 0")\
	X(ZERROR_NEGATIVE, "argument must be non-negative")


enum zerror
zerror(const char **desc)
{
	if (libzahl_error >= 0) {
		if (desc)
			*desc = strerror(libzahl_error);
		errno = libzahl_error;
		return ZERROR_ERRNO_SET;
	}

	if (desc) {
		switch (-libzahl_error) {
#define X(V, D) case V: *desc = D; break;
		LIST_ERRORS
#undef X
		default:
			abort();
		}
	}
	return -libzahl_error;
}