aboutsummaryrefslogtreecommitdiff
path: root/lib/error/names.c
blob: 9603210d9451f3f7feda4595f06cfa1af6760f2a (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "internals.h"

/* The array. */

#define UNKNOWN NULL, NULL

TIO_LOCAL_DATA(char const *) errors[] = {
	"tio_error_none",     "everything is okay",
	"tio_error_unknown",  "an unknown error has occurred",
	"tio_error_alloc",    "a memory allocation has failed",
	"tio_error_op",       "unsupported operation",
	"tio_error_arg",      "an argument was invalid",
	"tio_error_iter",     "no more elements in an iterator",
	"tio_error_notfound", "an element wasn't found",
	"tio_error_access",   "not enough privileges to operate",
	"tio_error_lock",     "a locking or unlocking operation has failed",

	UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
	UNKNOWN, UNKNOWN, UNKNOWN,

	"tio_error_stream",   "invalid/erroneous stream",
	"tio_error_read",     "a read operation has failed",
	"tio_error_write",    "a write operation has failed",
	"tio_error_seek",     "a seek operation has failed",
	"tio_error_end",      "an end of stream has been reached",
	"tio_error_timeout",  "a timeout has occurred",
	"tio_error_scsi",     "an SCSI operation has failed",
	"tio_error_usb",      "a USB operation has failed"
};

/* ---
 * Public functions.
 * --- */

/* `tio_error_name()`: get the error name. */

TIO_EXTERN(char const *) tio_error_name(int code)
{
	char const *nm;

	if (code >= ERROR_COUNT || !(nm = errors[code + code]))
		return ("(unknown libtio error)");
	return (nm);
}

/* `tio_error_desc()`: get the error description. */

TIO_EXTERN(char const *) tio_error_desc(int code)
{
	char const *ds;

	if (code >= ERROR_COUNT || !(ds = errors[code + code + 1]))
		return ("(unknown libtio error)");
	return (ds);
}