fdt_strerror.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * libfdt - Flat Device Tree manipulation
  3. * Copyright (C) 2006 David Gibson, IBM Corporation.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public License
  7. * as published by the Free Software Foundation; either version 2.1 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "libfdt_env.h"
  20. #include <fdt.h>
  21. #include <libfdt.h>
  22. #include "libfdt_internal.h"
  23. struct errtabent {
  24. const char *str;
  25. };
  26. #define ERRTABENT(val) \
  27. [(val)] = { .str = #val, }
  28. static struct errtabent errtable[] = {
  29. ERRTABENT(FDT_ERR_NOTFOUND),
  30. ERRTABENT(FDT_ERR_EXISTS),
  31. ERRTABENT(FDT_ERR_NOSPACE),
  32. ERRTABENT(FDT_ERR_BADOFFSET),
  33. ERRTABENT(FDT_ERR_BADPATH),
  34. ERRTABENT(FDT_ERR_BADSTATE),
  35. ERRTABENT(FDT_ERR_TRUNCATED),
  36. ERRTABENT(FDT_ERR_BADMAGIC),
  37. ERRTABENT(FDT_ERR_BADVERSION),
  38. ERRTABENT(FDT_ERR_BADSTRUCTURE),
  39. ERRTABENT(FDT_ERR_BADLAYOUT),
  40. };
  41. #define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0]))
  42. const char *fdt_strerror(int errval)
  43. {
  44. if (errval > 0)
  45. return "<valid offset/length>";
  46. else if (errval == 0)
  47. return "<no error>";
  48. else if (errval > -ERRTABSIZE) {
  49. const char *s = errtable[-errval].str;
  50. if (s)
  51. return s;
  52. }
  53. return "<unknown error>";
  54. }