14b169a6bSchristos /* sframe-error.c - Error messages. 24b169a6bSchristos 3*6817db7fSchristos Copyright (C) 2022-2024 Free Software Foundation, Inc. 44b169a6bSchristos 54b169a6bSchristos This file is part of libsframe. 64b169a6bSchristos 74b169a6bSchristos This program is free software; you can redistribute it and/or modify 84b169a6bSchristos it under the terms of the GNU General Public License as published by 94b169a6bSchristos the Free Software Foundation; either version 3 of the License, or 104b169a6bSchristos (at your option) any later version. 114b169a6bSchristos 124b169a6bSchristos This program is distributed in the hope that it will be useful, 134b169a6bSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 144b169a6bSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 154b169a6bSchristos GNU General Public License for more details. 164b169a6bSchristos 174b169a6bSchristos You should have received a copy of the GNU General Public License 184b169a6bSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 194b169a6bSchristos 204b169a6bSchristos #include "sframe-api.h" 214b169a6bSchristos #include <stddef.h> 224b169a6bSchristos #include <string.h> 234b169a6bSchristos 244b169a6bSchristos /* In this file, we want to treat the first item of the SFrame error 254b169a6bSchristos macro like subsequent items. */ 264b169a6bSchristos #define _SFRAME_FIRST(NAME, VALUE) _SFRAME_ITEM(NAME, VALUE) 274b169a6bSchristos 284b169a6bSchristos /* The error message strings, each in a unique structure member precisely big 294b169a6bSchristos enough for that error, plus a str member to access them all as a string 304b169a6bSchristos table. */ 314b169a6bSchristos 324b169a6bSchristos static const char *const _sframe_errlist[] = { 334b169a6bSchristos #define _SFRAME_ITEM(n, s) s, 344b169a6bSchristos _SFRAME_ERRORS 354b169a6bSchristos #undef _SFRAME_ITEM 364b169a6bSchristos }; 374b169a6bSchristos 384b169a6bSchristos const char * 394b169a6bSchristos sframe_errmsg (int error) 404b169a6bSchristos { 414b169a6bSchristos const char *str; 424b169a6bSchristos 434b169a6bSchristos if (error >= SFRAME_ERR_BASE && (error - SFRAME_ERR_BASE) < SFRAME_ERR_NERR) 444b169a6bSchristos str = _sframe_errlist[error - SFRAME_ERR_BASE]; 454b169a6bSchristos else 464b169a6bSchristos str = (const char *) strerror (error); 474b169a6bSchristos 484b169a6bSchristos return (str ? str : "Unknown error"); 494b169a6bSchristos } 50