1 /*
2 * errcode.c - convert an error code to a string
3 */
4
5 #include "config.h"
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include "e2p.h"
11
12 static const char *err_string[] = {
13 "",
14 "UNKNOWN", /* 1 */
15 "EIO", /* 2 */
16 "ENOMEM", /* 3 */
17 "EFSBADCRC", /* 4 */
18 "EFSCORRUPTED", /* 5 */
19 "ENOSPC", /* 6 */
20 "ENOKEY", /* 7 */
21 "EROFS", /* 8 */
22 "EFBIG", /* 9 */
23 "EEXIST", /* 10 */
24 "ERANGE", /* 11 */
25 "EOVERFLOW", /* 12 */
26 "EBUSY", /* 13 */
27 "ENOTDIR", /* 14 */
28 "ENOTEMPTY", /* 15 */
29 "ESHUTDOWN", /* 16 */
30 "EFAULT", /* 17 */
31 };
32
33 #define ARRAY_SIZE(array) \
34 (sizeof(array) / sizeof(array[0]))
35
36 /* Return the name of an encoding or NULL */
e2p_errcode2str(unsigned int err)37 const char *e2p_errcode2str(unsigned int err)
38 {
39 static char buf[32];
40
41 if (err < ARRAY_SIZE(err_string))
42 return err_string[err];
43
44 sprintf(buf, "UNKNOWN_ERRCODE_%u", err);
45 return buf;
46 }
47
48
49