fdt_strerror.c revision 318102
1367SN/A/* 2396SN/A * libfdt - Flat Device Tree manipulation 3367SN/A * Copyright (C) 2006 David Gibson, IBM Corporation. 4367SN/A * 5367SN/A * libfdt is dual licensed: you can use it either under the terms of 6367SN/A * the GPL, or the BSD license, at your option. 7367SN/A * 8367SN/A * a) This library is free software; you can redistribute it and/or 9367SN/A * modify it under the terms of the GNU General Public License as 10367SN/A * published by the Free Software Foundation; either version 2 of the 11367SN/A * License, or (at your option) any later version. 12367SN/A * 13367SN/A * This library is distributed in the hope that it will be useful, 14367SN/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 15367SN/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16367SN/A * GNU General Public License for more details. 17367SN/A * 18367SN/A * You should have received a copy of the GNU General Public 19367SN/A * License along with this library; if not, write to the Free 20367SN/A * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21367SN/A * MA 02110-1301 USA 22367SN/A * 23367SN/A * Alternatively, 24367SN/A * 25367SN/A * b) Redistribution and use in source and binary forms, with or 26367SN/A * without modification, are permitted provided that the following 27367SN/A * conditions are met: 28367SN/A * 29367SN/A * 1. Redistributions of source code must retain the above 30367SN/A * copyright notice, this list of conditions and the following 31367SN/A * disclaimer. 32367SN/A * 2. Redistributions in binary form must reproduce the above 33367SN/A * copyright notice, this list of conditions and the following 34367SN/A * disclaimer in the documentation and/or other materials 35367SN/A * provided with the distribution. 36367SN/A * 37367SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 38367SN/A * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 39367SN/A * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 40367SN/A * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41367SN/A * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 42367SN/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43367SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44367SN/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45367SN/A * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46367SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 47367SN/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 48367SN/A * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 49396SN/A * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50367SN/A */ 51367SN/A#include "libfdt_env.h" 52367SN/A 53367SN/A#include <fdt.h> 54367SN/A#include <libfdt.h> 55367SN/A 56367SN/A#include "libfdt_internal.h" 57396SN/A 58367SN/Astruct fdt_errtabent { 59367SN/A const char *str; 60367SN/A}; 61367SN/A 62367SN/A#define FDT_ERRTABENT(val) \ 63367SN/A [(val)] = { .str = #val, } 64367SN/A 65367SN/Astatic struct fdt_errtabent fdt_errtable[] = { 66396SN/A FDT_ERRTABENT(FDT_ERR_NOTFOUND), 67396SN/A FDT_ERRTABENT(FDT_ERR_EXISTS), 68367SN/A FDT_ERRTABENT(FDT_ERR_NOSPACE), 69367SN/A 70367SN/A FDT_ERRTABENT(FDT_ERR_BADOFFSET), 71367SN/A FDT_ERRTABENT(FDT_ERR_BADPATH), 72367SN/A FDT_ERRTABENT(FDT_ERR_BADPHANDLE), 73367SN/A FDT_ERRTABENT(FDT_ERR_BADSTATE), 74367SN/A 75367SN/A FDT_ERRTABENT(FDT_ERR_TRUNCATED), 76396SN/A FDT_ERRTABENT(FDT_ERR_BADMAGIC), 77367SN/A FDT_ERRTABENT(FDT_ERR_BADVERSION), 78367SN/A FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), 79367SN/A FDT_ERRTABENT(FDT_ERR_BADLAYOUT), 80367SN/A FDT_ERRTABENT(FDT_ERR_INTERNAL), 81367SN/A FDT_ERRTABENT(FDT_ERR_BADNCELLS), 82367SN/A FDT_ERRTABENT(FDT_ERR_BADVALUE), 83367SN/A FDT_ERRTABENT(FDT_ERR_BADOVERLAY), 84367SN/A FDT_ERRTABENT(FDT_ERR_NOPHANDLES), 85367SN/A}; 86367SN/A#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) 87367SN/A 88367SN/Aconst char *fdt_strerror(int errval) 89367SN/A{ 90367SN/A if (errval > 0) 91367SN/A return "<valid offset/length>"; 92367SN/A else if (errval == 0) 93367SN/A return "<no error>"; 94367SN/A else if (errval > -FDT_ERRTABSIZE) { 95367SN/A const char *s = fdt_errtable[-errval].str; 96367SN/A 97367SN/A if (s) 98367SN/A return s; 99367SN/A } 100367SN/A 101367SN/A return "<unknown error>"; 102367SN/A} 103367SN/A