11590Srgrimes/* sframe-error.c - Error messages.
21590Srgrimes
31590Srgrimes   Copyright (C) 2022-2024 Free Software Foundation, Inc.
41590Srgrimes
51590Srgrimes   This file is part of libsframe.
61590Srgrimes
71590Srgrimes   This program is free software; you can redistribute it and/or modify
81590Srgrimes   it under the terms of the GNU General Public License as published by
91590Srgrimes   the Free Software Foundation; either version 3 of the License, or
101590Srgrimes   (at your option) any later version.
111590Srgrimes
12263142Seadler   This program is distributed in the hope that it will be useful,
131590Srgrimes   but WITHOUT ANY WARRANTY; without even the implied warranty of
141590Srgrimes   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
151590Srgrimes   GNU General Public License for more details.
161590Srgrimes
171590Srgrimes   You should have received a copy of the GNU General Public License
181590Srgrimes   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
191590Srgrimes
201590Srgrimes#include "sframe-api.h"
211590Srgrimes#include <stddef.h>
221590Srgrimes#include <string.h>
231590Srgrimes
241590Srgrimes/* In this file, we want to treat the first item of the SFrame error
251590Srgrimes   macro like subsequent items.  */
261590Srgrimes#define _SFRAME_FIRST(NAME, VALUE) _SFRAME_ITEM(NAME, VALUE)
271590Srgrimes
281590Srgrimes/* The error message strings, each in a unique structure member precisely big
291590Srgrimes   enough for that error, plus a str member to access them all as a string
301590Srgrimes   table.  */
311590Srgrimes
321590Srgrimesstatic const char *const _sframe_errlist[] = {
331590Srgrimes#define _SFRAME_ITEM(n, s) s,
341590Srgrimes_SFRAME_ERRORS
351590Srgrimes#undef _SFRAME_ITEM
361590Srgrimes};
371590Srgrimes
381590Srgrimesconst char *
391590Srgrimessframe_errmsg (int error)
401590Srgrimes{
411590Srgrimes  const char *str;
421590Srgrimes
431590Srgrimes  if (error >= SFRAME_ERR_BASE && (error - SFRAME_ERR_BASE) < SFRAME_ERR_NERR)
441590Srgrimes    str = _sframe_errlist[error - SFRAME_ERR_BASE];
451590Srgrimes  else
461590Srgrimes    str = (const char *) strerror (error);
471590Srgrimes
481590Srgrimes  return (str ? str : "Unknown error");
49}
50