1 /* sframe-error.c - Error messages. 2 3 Copyright (C) 2022-2024 Free Software Foundation, Inc. 4 5 This file is part of libsframe. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20 #include "sframe-api.h" 21 #include <stddef.h> 22 #include <string.h> 23 24 /* In this file, we want to treat the first item of the SFrame error 25 macro like subsequent items. */ 26 #define _SFRAME_FIRST(NAME, VALUE) _SFRAME_ITEM(NAME, VALUE) 27 28 /* The error message strings, each in a unique structure member precisely big 29 enough for that error, plus a str member to access them all as a string 30 table. */ 31 32 static const char *const _sframe_errlist[] = { 33 #define _SFRAME_ITEM(n, s) s, 34 _SFRAME_ERRORS 35 #undef _SFRAME_ITEM 36 }; 37 38 const char * 39 sframe_errmsg (int error) 40 { 41 const char *str; 42 43 if (error >= SFRAME_ERR_BASE && (error - SFRAME_ERR_BASE) < SFRAME_ERR_NERR) 44 str = _sframe_errlist[error - SFRAME_ERR_BASE]; 45 else 46 str = (const char *) strerror (error); 47 48 return (str ? str : "Unknown error"); 49 } 50