You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

errno.c 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "etherboot.h"
  2. #include "errno.h"
  3. #include "vsprintf.h"
  4. /** @file
  5. *
  6. * Error codes and descriptions.
  7. *
  8. * This file provides the global variable #errno and the function
  9. * strerror(). These function much like their standard C library
  10. * equivalents.
  11. *
  12. * The error numbers used by Etherboot are a superset of those defined
  13. * by the PXE specification version 2.1. See errno.h for a listing of
  14. * the error values.
  15. *
  16. * To save space in ROM images, error string tables are optional. Use
  17. * the ERRORMSG_XXX options in config.h to select which error string
  18. * tables you want to include. If an error string table is omitted,
  19. * strerror() will simply return the text "Error 0x<errno>".
  20. *
  21. */
  22. /**
  23. * Global "last error" number.
  24. *
  25. * This is valid only when a function has just returned indicating a
  26. * failure.
  27. *
  28. */
  29. int errno;
  30. static struct errortab errortab_start[0] __table_start(errortab);
  31. static struct errortab errortab_end[0] __table_end(errortab);
  32. /**
  33. * Retrieve string representation of error number.
  34. *
  35. * @v errno Error number
  36. * @ret strerror Pointer to error text
  37. *
  38. * If the error is not found in the linked-in error tables, generates
  39. * a generic "Error 0x<errno>" message.
  40. *
  41. * The pointer returned by strerror() is valid only until the next
  42. * call to strerror().
  43. *
  44. */
  45. const char * strerror ( int errno ) {
  46. static char *generic_message = "Error 0x0000";
  47. struct errortab *errortab;
  48. for ( errortab = errortab_start ; errortab < errortab_end ;
  49. errortab++ ) {
  50. if ( errortab->errno == errno )
  51. return errortab->text;
  52. }
  53. sprintf ( generic_message + 8, "%hx", errno );
  54. return generic_message;
  55. }