device: Add functions to read/write raw configuration data.
[libjaylink.git] / libjaylink / error.c
blob0c5934bb5591a58f8c5aa270284e17ed95aedfc3
1 /*
2 * This file is part of the libjaylink project.
4 * Copyright (C) 2014 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 3 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 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 const char *jaylink_strerror(int error_code)
40 switch (error_code) {
41 case JAYLINK_OK:
42 return "no error";
43 case JAYLINK_ERR:
44 return "unspecified error";
45 case JAYLINK_ERR_MALLOC:
46 return "memory allocation error";
47 case JAYLINK_ERR_ARG:
48 return "invalid argument";
49 case JAYLINK_ERR_TIMEOUT:
50 return "timeout occurred";
51 default:
52 return "unknown error";
56 /**
57 * Return the name of a libjaylink error code.
59 * @param error_code A libjaylink error code. See #jaylink_error for valid
60 * values.
62 * @return A string which contains the name for the given error code or the
63 * string <i>unknown error code</i> if the error code is not known. The
64 * string is null-terminated and must not be free'd by the caller.
66 const char *jaylink_strerror_name(int error_code)
68 switch (error_code) {
69 case JAYLINK_OK:
70 return "JAYLINK_OK";
71 case JAYLINK_ERR:
72 return "JAYLINK_ERR";
73 case JAYLINK_ERR_MALLOC:
74 return "JAYLINK_ERR_MALLOC";
75 case JAYLINK_ERR_ARG:
76 return "JAYLINK_ERR_ARG";
77 case JAYLINK_ERR_TIMEOUT:
78 return "JAYLINK_ERR_TIMEOUT";
79 default:
80 return "unknown error code";