fdt_strerror.c revision 9537:ad5b3252dcc6
1/* 2 * libfdt - Flat Device Tree manipulation 3 * Copyright (C) 2006 David Gibson, IBM Corporation. 4 * 5 * Redistribution and use in source and binary forms, with or 6 * without modification, are permitted provided that the following 7 * conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer. 12 * 2. Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following 14 * disclaimer in the documentation and/or other materials 15 * provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 18 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31#include <fdt.h> 32#include <libfdt.h> 33 34#include "libfdt_env.h" 35#include "libfdt_internal.h" 36 37struct fdt_errtabent { 38 const char *str; 39}; 40 41#define FDT_ERRTABENT(val) \ 42 [(val)] = { .str = #val, } 43 44static struct fdt_errtabent fdt_errtable[] = { 45 FDT_ERRTABENT(FDT_ERR_NOTFOUND), 46 FDT_ERRTABENT(FDT_ERR_EXISTS), 47 FDT_ERRTABENT(FDT_ERR_NOSPACE), 48 49 FDT_ERRTABENT(FDT_ERR_BADOFFSET), 50 FDT_ERRTABENT(FDT_ERR_BADPATH), 51 FDT_ERRTABENT(FDT_ERR_BADSTATE), 52 53 FDT_ERRTABENT(FDT_ERR_TRUNCATED), 54 FDT_ERRTABENT(FDT_ERR_BADMAGIC), 55 FDT_ERRTABENT(FDT_ERR_BADVERSION), 56 FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), 57 FDT_ERRTABENT(FDT_ERR_BADLAYOUT), 58}; 59#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) 60 61const char *fdt_strerror(int errval) 62{ 63 if (errval > 0) 64 return "<valid offset/length>"; 65 else if (errval == 0) 66 return "<no error>"; 67 else if (errval > -FDT_ERRTABSIZE) { 68 const char *s = fdt_errtable[-errval].str; 69 70 if (s) 71 return s; 72 } 73 74 return "<unknown error>"; 75} 76