2 * This file is part of the libsigrokdecode project.
4 * Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.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/>.
21 #include "libsigrokdecode.h"
26 * Error handling in libsigrokdecode.
30 * @defgroup grp_error Error handling
32 * Error handling in libsigrokdecode.
34 * libsigrokdecode functions usually return @ref SRD_OK upon success, or a
35 * negative error code on failure.
41 * Return a human-readable error string for the given libsigrokdecode error
44 * @param error_code A libsigrokdecode error code number, such as
47 * @return A const string containing a short, human-readable (English)
48 * description of the error, such as "memory allocation error".
49 * The string must NOT be free'd by the caller!
51 * @see srd_strerror_name
55 SRD_API
const char *srd_strerror(int error_code
)
60 * Note: All defined SRD_* error macros from libsigrokdecode.h must
61 * have an entry in this function, as well as in srd_strerror_name().
69 str
= "generic/unspecified error";
72 str
= "memory allocation error";
75 str
= "invalid argument";
78 str
= "internal error";
81 str
= "Python API error";
83 case SRD_ERR_DECODERS_DIR
:
84 str
= "decoders directory access error";
87 str
= "unknown error";
95 * Return the "name" string of the given libsigrokdecode error code.
97 * For example, the "name" of the SRD_ERR_MALLOC error code is
98 * "SRD_ERR_MALLOC", the name of the SRD_OK code is "SRD_OK", and so on.
100 * This function can be used for various purposes where the "name" string of
101 * a libsigrokdecode error code is useful.
103 * @param error_code A libsigrokdecode error code number, such as
106 * @return A const string containing the "name" of the error code as string.
107 * The string must NOT be free'd by the caller!
113 SRD_API
const char *srd_strerror_name(int error_code
)
118 * Note: All defined SRD_* error macros from libsigrokdecode.h must
119 * have an entry in this function, as well as in srd_strerror().
122 switch (error_code
) {
130 str
= "SRD_ERR_MALLOC";
139 str
= "SRD_ERR_PYTHON";
141 case SRD_ERR_DECODERS_DIR
:
142 str
= "SRD_ERR_DECODERS_DIR";
145 str
= "unknown error code";