aboutsummaryrefslogtreecommitdiff
path: root/lib/error.c
blob: 155a354972831e728b9dab757534763929d70c63 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* ****************************************************************************
 * errors.c -- error strings.
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of libcasio.
 * libcasio is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3.0 of the License,
 * or (at your option) any later version.
 *
 * libcasio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with libcasio; if not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#define LIBCASIO_NO_STRERROR
#include "internals.h"

#define ARR_SIZE 0x74
#define UNKNOWN NULL, NULL

const char* CASIO_EXPORT casio_error_strings[128] = {
	/* Miscallaneous errors. */

	"casio_error_none",    "no error has occured",
	"casio_error_unknown", "an unknown error has occured",
	"casio_error_alloc",   "a memory allocation has failed",
	"casio_error_op",      "this operation is unsupported",
	"casio_error_arg",     "an argument was invalid",
	"casio_error_lock",    "mutex is locked",
	"casio_error_iter",    "no more elements in the iterator",

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

	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

	/* Stream errors. */

	"casio_error_stream",  "the stream is invalid/no (more) stream",
	"casio_error_read",    "a read operation on the stream has failed",
	"casio_error_write",   "a write operation on the stream has failed",
	"casio_error_seek",    "a seek operation on the stream has failed",
	"casio_error_timeout", "a timeout has occurred",
	"casio_error_access",  "could not get access to the device",
	"casio_error_eof",     "an end of file event has occured",
	"casio_error_scsi",    "a SCSI operation on the stream has failed",
	"casio_error_usb",     "a USB operation on the stream has failed",

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

	/* Link errors. */

	"casio_error_init",    "the link was uninitialized",
	"casio_error_shift",   "illegal double shifting",
	"casio_error_damned",  "irrecoverable link error",
	"casio_error_int",     "interrupted by user",
	"casio_error_active",  "not in active/passive mode",
	"casio_error_noow",    "denied overwrite",
	"casio_error_command", "unsupported command",

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

	/* Filesystem errors. */

	"casio_error_device",   "unsupported storage device",
	"casio_error_fullmem",  "full memory",
	"casio_error_notfound", "file not found",
	"casio_error_empty",    "empty files aren't allowed",

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

	/* Decoding errors. */

	"casio_error_magic",    "corrupted or unknown file format",
	"casio_error_csum",     "invalid checksum",
	"casio_error_wrong",    "not one of the allowed file types",
	"casio_error_seq",      "sequence error",
	"casio_error_noeq",     "character does not translate"
};

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

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

CASIO_EXTERN(char const *) casio_error_name(int code)
{
	char const *nm;

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

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

CASIO_EXTERN(char const *) casio_error_desc(int code)
{
	char const *ds;

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