Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

strerror.c 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <errno.h>
  2. #include <string.h>
  3. #include <vsprintf.h>
  4. #include <gpxe/errortab.h>
  5. /** @file
  6. *
  7. * Error descriptions.
  8. *
  9. * The error numbers used by Etherboot are a superset of those defined
  10. * by the PXE specification version 2.1. See errno.h for a listing of
  11. * the error values.
  12. *
  13. * To save space in ROM images, error string tables are optional. Use
  14. * the ERRORMSG_XXX options in config.h to select which error string
  15. * tables you want to include. If an error string table is omitted,
  16. * strerror() will simply return the text "Error 0x<errno>".
  17. *
  18. */
  19. static struct errortab errortab_start[0]
  20. __table_start ( struct errortab, errortab );
  21. static struct errortab errortab_end[0]
  22. __table_end ( struct errortab, errortab );
  23. /**
  24. * Retrieve string representation of error number.
  25. *
  26. * @v errno Error number
  27. * @ret strerror Pointer to error text
  28. *
  29. * If the error is not found in the linked-in error tables, generates
  30. * a generic "Error 0x<errno>" message.
  31. *
  32. * The pointer returned by strerror() is valid only until the next
  33. * call to strerror().
  34. *
  35. */
  36. const char * strerror ( int errno ) {
  37. static char *generic_message = "Error 0x0000";
  38. struct errortab *errortab;
  39. /* Allow for strerror(rc) as well as strerror(errno) */
  40. if ( errno < 0 )
  41. errno = -errno;
  42. for ( errortab = errortab_start ; errortab < errortab_end ;
  43. errortab++ ) {
  44. if ( errortab->errno == errno )
  45. return errortab->text;
  46. }
  47. sprintf ( generic_message + 8, "%hx", errno );
  48. return generic_message;
  49. }
  50. /** The most common errors */
  51. struct errortab common_errors[] __errortab = {
  52. { 0, "No error" },
  53. { ENOMEM, "Out of memory" },
  54. { EINVAL, "Invalid argument" },
  55. { ENOSPC, "No space left on device" },
  56. { EIO, "Input/output error" },
  57. { EACCES, "Permission denied" },
  58. { ENOENT, "File not found" },
  59. { ENETUNREACH, "Network unreachable" },
  60. };