PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/include/qapi/error.h

https://github.com/Bludge0n/qemu
C Header | 103 lines | 32 code | 15 blank | 56 comment | 0 complexity | d323e21cfed5099ad58f690d2b6f93a3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. /*
  2. * QEMU Error Objects
  3. *
  4. * Copyright IBM, Corp. 2011
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU LGPL, version 2. See
  10. * the COPYING.LIB file in the top-level directory.
  11. */
  12. #ifndef ERROR_H
  13. #define ERROR_H
  14. #include "qemu/compiler.h"
  15. #include "qapi-types.h"
  16. #include <stdbool.h>
  17. /**
  18. * A class representing internal errors within QEMU. An error has a ErrorClass
  19. * code and a human message.
  20. */
  21. typedef struct Error Error;
  22. /**
  23. * Set an indirect pointer to an error given a ErrorClass value and a
  24. * printf-style human message. This function is not meant to be used outside
  25. * of QEMU.
  26. */
  27. void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
  28. GCC_FMT_ATTR(3, 4);
  29. /**
  30. * Set an indirect pointer to an error given a ErrorClass value and a
  31. * printf-style human message, followed by a strerror() string if
  32. * @os_error is not zero.
  33. */
  34. void error_set_errno(Error **errp, int os_error, ErrorClass err_class,
  35. const char *fmt, ...) GCC_FMT_ATTR(4, 5);
  36. #ifdef _WIN32
  37. /**
  38. * Set an indirect pointer to an error given a ErrorClass value and a
  39. * printf-style human message, followed by a g_win32_error_message() string if
  40. * @win32_err is not zero.
  41. */
  42. void error_set_win32(Error **errp, int win32_err, ErrorClass err_class,
  43. const char *fmt, ...) GCC_FMT_ATTR(4, 5);
  44. #endif
  45. /**
  46. * Same as error_set(), but sets a generic error
  47. */
  48. #define error_setg(errp, fmt, ...) \
  49. error_set(errp, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
  50. #define error_setg_errno(errp, os_error, fmt, ...) \
  51. error_set_errno(errp, os_error, ERROR_CLASS_GENERIC_ERROR, \
  52. fmt, ## __VA_ARGS__)
  53. #ifdef _WIN32
  54. #define error_setg_win32(errp, win32_err, fmt, ...) \
  55. error_set_win32(errp, win32_err, ERROR_CLASS_GENERIC_ERROR, \
  56. fmt, ## __VA_ARGS__)
  57. #endif
  58. /**
  59. * Helper for open() errors
  60. */
  61. void error_setg_file_open(Error **errp, int os_errno, const char *filename);
  62. /*
  63. * Get the error class of an error object.
  64. */
  65. ErrorClass error_get_class(const Error *err);
  66. /**
  67. * Returns an exact copy of the error passed as an argument.
  68. */
  69. Error *error_copy(const Error *err);
  70. /**
  71. * Get a human readable representation of an error object.
  72. */
  73. const char *error_get_pretty(Error *err);
  74. /**
  75. * Propagate an error to an indirect pointer to an error. This function will
  76. * always transfer ownership of the error reference and handles the case where
  77. * dst_err is NULL correctly. Errors after the first are discarded.
  78. */
  79. void error_propagate(Error **dst_errp, Error *local_err);
  80. /**
  81. * Free an error object.
  82. */
  83. void error_free(Error *err);
  84. /**
  85. * If passed to error_set and friends, abort().
  86. */
  87. extern Error *error_abort;
  88. #endif