PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/include/error.h

https://github.com/megous/spkg
C Header | 99 lines | 29 code | 19 blank | 51 comment | 0 complexity | b5912541eea0ab31d9d9fee0269432db MD5 | raw file
  1. /*----------------------------------------------------------------------*\
  2. |* spkg - The Unofficial Slackware Linux Package Manager *|
  3. |* designed by Ondøej Jirman, 2005 *|
  4. |*----------------------------------------------------------------------*|
  5. |* No copy/usage restrictions are imposed on anybody. *|
  6. \*----------------------------------------------------------------------*/
  7. /** @defgroup err_api Error Handling API
  8. This is common error handling API for all parts of spkg.
  9. */
  10. /** @addtogroup err_api */
  11. /*! @{ */
  12. #ifndef SPKG__ERROR_H
  13. #define SPKG__ERROR_H
  14. #include <glib.h>
  15. G_BEGIN_DECLS
  16. #define E_OK 0 /**< all ok */
  17. #define E_ERROR 1 /**< nonfatal error */
  18. #define E_BADARG 2 /**< invalid function arguments */
  19. #define E_FATAL 4 /**< fatal error */
  20. #define E_BREAK 5 /**< terminated by signal */
  21. #define E_PASS (-1) /**< leave previous error code (useful for longjmp error handling) */
  22. #define E(n) (1<<(n+8)) /**< helper macro for error number definitions */
  23. struct error;
  24. /** Create new error object.
  25. *
  26. * @return Error object.
  27. */
  28. extern struct error* e_new();
  29. /** Free error object.
  30. *
  31. * @param e Error object.
  32. */
  33. extern void e_free(struct error* e);
  34. /** Get string representation of the error.
  35. *
  36. * @return Error string on error, 0 otherwise
  37. */
  38. extern gchar* e_string(struct error* e);
  39. /** Get numeric representation of the error.
  40. *
  41. * @return Numeric representation of the error.
  42. */
  43. extern gint e_errno(struct error* e);
  44. /** Add error to the error object.
  45. *
  46. * @param e Error object.
  47. * @param context Error context. (in which library it occured)
  48. * @param function Error function (in which function it occured)
  49. * @param errnum Error number. (error type)
  50. * @param errfmt Just like in printf.
  51. */
  52. extern void e_add(
  53. struct error* e,
  54. const char* context,
  55. const char* function,
  56. gint errnum,
  57. gchar* errfmt,
  58. ...
  59. ) G_GNUC_PRINTF (5, 6);
  60. /** Clean error.
  61. *
  62. * @param e Error object.
  63. */
  64. extern void e_clean(struct error* e);
  65. /** Print error message.
  66. *
  67. * @param e Error object.
  68. */
  69. extern void e_print(struct error* e);
  70. /** Returns true if no error occured.
  71. *
  72. * @param e Error object.
  73. * @return true if ok.
  74. */
  75. extern gint e_ok(struct error* e);
  76. G_END_DECLS
  77. #endif
  78. /*! @} */