Patrick Uiterwijk | 84c7f7e | 2020-03-21 19:00:05 +0100 | [diff] [blame^] | 1 | /*============================================================================== |
| 2 | err_to_str.c -- strings names for errors |
| 3 | |
| 4 | Copyright (c) 2020, Patrick Uiterwijk. All rights reserved. |
| 5 | |
| 6 | SPDX-License-Identifier: BSD-3-Clause |
| 7 | |
| 8 | See BSD-3-Clause license in README.md |
| 9 | |
| 10 | Created on 3/21/20 |
| 11 | =============================================================================*/ |
| 12 | |
| 13 | #include "qcbor.h" |
| 14 | |
| 15 | #define _ERR_TO_STR(errpart) case QCBOR_##errpart: return "QCBOR_" #errpart; |
| 16 | |
| 17 | const char *qcbor_err_to_str(QCBORError err) { |
| 18 | switch (err) { |
| 19 | _ERR_TO_STR(SUCCESS) |
| 20 | _ERR_TO_STR(ERR_BUFFER_TOO_SMALL) |
| 21 | _ERR_TO_STR(ERR_ARRAY_NESTING_TOO_DEEP) |
| 22 | _ERR_TO_STR(ERR_ARRAY_TOO_LONG) |
| 23 | _ERR_TO_STR(ERR_TOO_MANY_CLOSES) |
| 24 | _ERR_TO_STR(ERR_UNSUPPORTED) |
| 25 | _ERR_TO_STR(ERR_HIT_END) |
| 26 | _ERR_TO_STR(ERR_BUFFER_TOO_LARGE) |
| 27 | _ERR_TO_STR(ERR_INT_OVERFLOW) |
| 28 | _ERR_TO_STR(ERR_MAP_LABEL_TYPE) |
| 29 | _ERR_TO_STR(ERR_ARRAY_OR_MAP_STILL_OPEN) |
| 30 | _ERR_TO_STR(ERR_DATE_OVERFLOW) |
| 31 | _ERR_TO_STR(ERR_BAD_TYPE_7) |
| 32 | _ERR_TO_STR(ERR_BAD_OPT_TAG) |
| 33 | _ERR_TO_STR(ERR_EXTRA_BYTES) |
| 34 | _ERR_TO_STR(ERR_CLOSE_MISMATCH) |
| 35 | _ERR_TO_STR(ERR_NO_STRING_ALLOCATOR) |
| 36 | _ERR_TO_STR(ERR_INDEFINITE_STRING_CHUNK) |
| 37 | _ERR_TO_STR(ERR_STRING_ALLOCATE) |
| 38 | _ERR_TO_STR(ERR_BAD_BREAK) |
| 39 | _ERR_TO_STR(ERR_TOO_MANY_TAGS) |
| 40 | _ERR_TO_STR(ERR_BAD_INT) |
| 41 | _ERR_TO_STR(ERR_NO_MORE_ITEMS) |
| 42 | _ERR_TO_STR(ERR_BAD_EXP_AND_MANTISSA) |
| 43 | _ERR_TO_STR(ERR_STRING_TOO_LONG) |
| 44 | |
| 45 | default: |
| 46 | return "Invalid error"; |
| 47 | } |
| 48 | } |