diff options
author | Marc Schink <jaylink-dev@marcschink.de> | 2014-10-08 07:00:12 -0400 |
---|---|---|
committer | Marc Schink <jaylink-dev@marcschink.de> | 2015-03-02 03:20:28 -0500 |
commit | e15148d2eec4ae897d0fc857253f3cf766a71f23 (patch) | |
tree | 34646781d15bba09739a925ba6860f1d8593c211 /libjaylink/error.c | |
parent | 8c36783432fff9cc413f9576e72af7d52471bc17 (diff) | |
download | libjaylink-e15148d2eec4ae897d0fc857253f3cf766a71f23.zip libjaylink-e15148d2eec4ae897d0fc857253f3cf766a71f23.tar.gz libjaylink-e15148d2eec4ae897d0fc857253f3cf766a71f23.tar.bz2 |
Add functions for error handling.
Diffstat (limited to 'libjaylink/error.c')
-rw-r--r-- | libjaylink/error.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/libjaylink/error.c b/libjaylink/error.c new file mode 100644 index 0000000..0c5934b --- /dev/null +++ b/libjaylink/error.c @@ -0,0 +1,82 @@ +/* + * This file is part of the libjaylink project. + * + * Copyright (C) 2014 Marc Schink <jaylink-dev@marcschink.de> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "libjaylink.h" + +/** + * @file + * + * Error handling. + */ + +/** + * Return a human-readable description of a libjaylink error code. + * + * @param error_code A libjaylink error code. See #jaylink_error for valid + * values. + * + * @return A string which describes the given error code or the string + * <i>unknown error</i> if the error code is not known. The string is + * null-terminated and must not be free'd by the caller. + */ +const char *jaylink_strerror(int error_code) +{ + switch (error_code) { + case JAYLINK_OK: + return "no error"; + case JAYLINK_ERR: + return "unspecified error"; + case JAYLINK_ERR_MALLOC: + return "memory allocation error"; + case JAYLINK_ERR_ARG: + return "invalid argument"; + case JAYLINK_ERR_TIMEOUT: + return "timeout occurred"; + default: + return "unknown error"; + } +} + +/** + * Return the name of a libjaylink error code. + * + * @param error_code A libjaylink error code. See #jaylink_error for valid + * values. + * + * @return A string which contains the name for the given error code or the + * string <i>unknown error code</i> if the error code is not known. The + * string is null-terminated and must not be free'd by the caller. + */ +const char *jaylink_strerror_name(int error_code) +{ + switch (error_code) { + case JAYLINK_OK: + return "JAYLINK_OK"; + case JAYLINK_ERR: + return "JAYLINK_ERR"; + case JAYLINK_ERR_MALLOC: + return "JAYLINK_ERR_MALLOC"; + case JAYLINK_ERR_ARG: + return "JAYLINK_ERR_ARG"; + case JAYLINK_ERR_TIMEOUT: + return "JAYLINK_ERR_TIMEOUT"; + default: + return "unknown error code"; + } +} |