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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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] __table_start(errortab);
  20. static struct errortab errortab_end[0] __table_end(errortab);
  21. /**
  22. * Retrieve string representation of error number.
  23. *
  24. * @v errno Error number
  25. * @ret strerror Pointer to error text
  26. *
  27. * If the error is not found in the linked-in error tables, generates
  28. * a generic "Error 0x<errno>" message.
  29. *
  30. * The pointer returned by strerror() is valid only until the next
  31. * call to strerror().
  32. *
  33. */
  34. const char * strerror ( int errno ) {
  35. static char *generic_message = "Error 0x0000";
  36. struct errortab *errortab;
  37. /* Allow for strerror(rc) as well as strerror(errno) */
  38. if ( errno < 0 )
  39. errno = -errno;
  40. for ( errortab = errortab_start ; errortab < errortab_end ;
  41. errortab++ ) {
  42. if ( errortab->errno == errno )
  43. return errortab->text;
  44. }
  45. sprintf ( generic_message + 8, "%hx", errno );
  46. return generic_message;
  47. }
  48. /** The most common errors */
  49. struct errortab enoem __errortab = { ENOMEM, "Out of memory" };
  50. struct errortab einval __errortab = { EINVAL, "Invalid argument" };
  51. struct errortab enospc __errortab = { ENOSPC, "No space left on device" };
  52. struct errortab eio __errortab = { EIO, "Input/output error" };
  53. struct errortab eacces __errortab = { EACCES, "Permission denied" };