Add jaylink_device_get_usb_bus_ports()
[libjaylink.git] / libjaylink / error.c
blob2c696fc28d59f62086221b49f8b638e2d5f582a4
1 /*
2 * This file is part of the libjaylink project.
4 * Copyright (C) 2014-2015 Marc Schink <jaylink-dev@marcschink.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "libjaylink.h"
22 /**
23 * @file
25 * Error handling.
28 /**
29 * Return a human-readable description of a libjaylink error code.
31 * @param[in] error_code A libjaylink error code. See #jaylink_error for valid
32 * values.
34 * @return A string which describes the given error code, or the string
35 * <i>unknown error</i> if the error code is not known. The string is
36 * null-terminated and must not be free'd by the caller.
38 * @since 0.1.0
40 JAYLINK_API const char *jaylink_strerror(int error_code)
42 switch (error_code) {
43 case JAYLINK_OK:
44 return "no error";
45 case JAYLINK_ERR:
46 return "unspecified error";
47 case JAYLINK_ERR_ARG:
48 return "invalid argument";
49 case JAYLINK_ERR_MALLOC:
50 return "memory allocation error";
51 case JAYLINK_ERR_TIMEOUT:
52 return "timeout occurred";
53 case JAYLINK_ERR_PROTO:
54 return "protocol violation";
55 case JAYLINK_ERR_NOT_AVAILABLE:
56 return "entity not available";
57 case JAYLINK_ERR_NOT_SUPPORTED:
58 return "operation not supported";
59 case JAYLINK_ERR_IO:
60 return "input/output error";
61 case JAYLINK_ERR_DEV:
62 return "device: unspecified error";
63 case JAYLINK_ERR_DEV_NOT_SUPPORTED:
64 return "device: operation not supported";
65 case JAYLINK_ERR_DEV_NOT_AVAILABLE:
66 return "device: entity not available";
67 case JAYLINK_ERR_DEV_NO_MEMORY:
68 return "device: not enough memory to perform operation";
69 default:
70 return "unknown error";
74 /**
75 * Return the name of a libjaylink error code.
77 * @param[in] error_code A libjaylink error code. See #jaylink_error for valid
78 * values.
80 * @return A string which contains the name for the given error code, or the
81 * string <i>unknown error code</i> if the error code is not known. The
82 * string is null-terminated and must not be free'd by the caller.
84 * @since 0.1.0
86 JAYLINK_API const char *jaylink_strerror_name(int error_code)
88 switch (error_code) {
89 case JAYLINK_OK:
90 return "JAYLINK_OK";
91 case JAYLINK_ERR:
92 return "JAYLINK_ERR";
93 case JAYLINK_ERR_ARG:
94 return "JAYLINK_ERR_ARG";
95 case JAYLINK_ERR_MALLOC:
96 return "JAYLINK_ERR_MALLOC";
97 case JAYLINK_ERR_TIMEOUT:
98 return "JAYLINK_ERR_TIMEOUT";
99 case JAYLINK_ERR_PROTO:
100 return "JAYLINK_ERR_PROTO";
101 case JAYLINK_ERR_NOT_AVAILABLE:
102 return "JAYLINK_ERR_NOT_AVAILABLE";
103 case JAYLINK_ERR_NOT_SUPPORTED:
104 return "JAYLINK_ERR_NOT_SUPPORTED";
105 case JAYLINK_ERR_IO:
106 return "JAYLINK_ERR_IO";
107 case JAYLINK_ERR_DEV:
108 return "JAYLINK_ERR_DEV";
109 case JAYLINK_ERR_DEV_NOT_SUPPORTED:
110 return "JAYLINK_ERR_DEV_NOT_SUPPORTED";
111 case JAYLINK_ERR_DEV_NOT_AVAILABLE:
112 return "JAYLINK_ERR_DEV_NOT_AVAILABLE";
113 case JAYLINK_ERR_DEV_NO_MEMORY:
114 return "JAYLINK_ERR_DEV_NO_MEMORY";
115 default:
116 return "unknown error code";