🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

163 lines
5.1 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_error.h
  20. *
  21. * Simple error message routines for SDL.
  22. */
  23. #ifndef SDL_error_h_
  24. #define SDL_error_h_
  25. #include "SDL_stdinc.h"
  26. #include "begin_code.h"
  27. /* Set up for C function definitions, even when using C++ */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Public functions */
  32. /**
  33. * Set the SDL error message for the current thread.
  34. *
  35. * Calling this function will replace any previous error message that was set.
  36. *
  37. * This function always returns -1, since SDL frequently uses -1 to signify an
  38. * failing result, leading to this idiom:
  39. *
  40. * ```c
  41. * if (error_code) {
  42. * return SDL_SetError("This operation has failed: %d", error_code);
  43. * }
  44. * ```
  45. *
  46. * \param fmt a printf()-style message format string
  47. * \param ... additional parameters matching % tokens in the `fmt` string, if
  48. * any
  49. * \returns always -1.
  50. *
  51. * \since This function is available since SDL 2.0.0.
  52. *
  53. * \sa SDL_ClearError
  54. * \sa SDL_GetError
  55. */
  56. extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
  57. /**
  58. * Retrieve a message about the last error that occurred on the current
  59. * thread.
  60. *
  61. * It is possible for multiple errors to occur before calling SDL_GetError().
  62. * Only the last error is returned.
  63. *
  64. * The message is only applicable when an SDL function has signaled an error.
  65. * You must check the return values of SDL function calls to determine when to
  66. * appropriately call SDL_GetError(). You should *not* use the results of
  67. * SDL_GetError() to decide if an error has occurred! Sometimes SDL will set
  68. * an error string even when reporting success.
  69. *
  70. * SDL will *not* clear the error string for successful API calls. You *must*
  71. * check return values for failure cases before you can assume the error
  72. * string applies.
  73. *
  74. * Error strings are set per-thread, so an error set in a different thread
  75. * will not interfere with the current thread's operation.
  76. *
  77. * The returned string is internally allocated and must not be freed by the
  78. * application.
  79. *
  80. * \returns a message with information about the specific error that occurred,
  81. * or an empty string if there hasn't been an error message set since
  82. * the last call to SDL_ClearError(). The message is only applicable
  83. * when an SDL function has signaled an error. You must check the
  84. * return values of SDL function calls to determine when to
  85. * appropriately call SDL_GetError().
  86. *
  87. * \since This function is available since SDL 2.0.0.
  88. *
  89. * \sa SDL_ClearError
  90. * \sa SDL_SetError
  91. */
  92. extern DECLSPEC const char *SDLCALL SDL_GetError(void);
  93. /**
  94. * Get the last error message that was set for the current thread.
  95. *
  96. * This allows the caller to copy the error string into a provided buffer, but
  97. * otherwise operates exactly the same as SDL_GetError().
  98. *
  99. * \param errstr A buffer to fill with the last error message that was set for
  100. * the current thread
  101. * \param maxlen The size of the buffer pointed to by the errstr parameter
  102. * \returns the pointer passed in as the `errstr` parameter.
  103. *
  104. * \since This function is available since SDL 2.0.14.
  105. *
  106. * \sa SDL_GetError
  107. */
  108. extern DECLSPEC char * SDLCALL SDL_GetErrorMsg(char *errstr, int maxlen);
  109. /**
  110. * Clear any previous error message for this thread.
  111. *
  112. * \since This function is available since SDL 2.0.0.
  113. *
  114. * \sa SDL_GetError
  115. * \sa SDL_SetError
  116. */
  117. extern DECLSPEC void SDLCALL SDL_ClearError(void);
  118. /**
  119. * \name Internal error functions
  120. *
  121. * \internal
  122. * Private error reporting function - used internally.
  123. */
  124. /* @{ */
  125. #define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
  126. #define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
  127. #define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
  128. typedef enum
  129. {
  130. SDL_ENOMEM,
  131. SDL_EFREAD,
  132. SDL_EFWRITE,
  133. SDL_EFSEEK,
  134. SDL_UNSUPPORTED,
  135. SDL_LASTERROR
  136. } SDL_errorcode;
  137. /* SDL_Error() unconditionally returns -1. */
  138. extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code);
  139. /* @} *//* Internal error functions */
  140. /* Ends C function definitions when using C++ */
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #include "close_code.h"
  145. #endif /* SDL_error_h_ */
  146. /* vi: set ts=4 sw=4 expandtab: */