SDL_error.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 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. * \brief Set the error message for the current thread
  34. *
  35. * \return -1, there is no error handling for this function
  36. */
  37. extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
  38. /**
  39. * \brief Get the last error message that was set
  40. *
  41. * SDL API functions may set error messages and then succeed, so you should
  42. * only use the error value if a function fails.
  43. *
  44. * This returns a pointer to a static buffer for convenience and should not
  45. * be called by multiple threads simultaneously.
  46. *
  47. * \return a pointer to the last error message that was set
  48. */
  49. extern DECLSPEC const char *SDLCALL SDL_GetError(void);
  50. /**
  51. * \brief Get the last error message that was set for the current thread
  52. *
  53. * SDL API functions may set error messages and then succeed, so you should
  54. * only use the error value if a function fails.
  55. *
  56. * \param errstr A buffer to fill with the last error message that was set
  57. * for the current thread
  58. * \param maxlen The size of the buffer pointed to by the errstr parameter
  59. *
  60. * \return errstr
  61. */
  62. extern DECLSPEC char * SDLCALL SDL_GetErrorMsg(char *errstr, int maxlen);
  63. /**
  64. * \brief Clear the error message for the current thread
  65. */
  66. extern DECLSPEC void SDLCALL SDL_ClearError(void);
  67. /**
  68. * \name Internal error functions
  69. *
  70. * \internal
  71. * Private error reporting function - used internally.
  72. */
  73. /* @{ */
  74. #define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
  75. #define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
  76. #define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
  77. typedef enum
  78. {
  79. SDL_ENOMEM,
  80. SDL_EFREAD,
  81. SDL_EFWRITE,
  82. SDL_EFSEEK,
  83. SDL_UNSUPPORTED,
  84. SDL_LASTERROR
  85. } SDL_errorcode;
  86. /* SDL_Error() unconditionally returns -1. */
  87. extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code);
  88. /* @} *//* Internal error functions */
  89. /* Ends C function definitions when using C++ */
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #include "close_code.h"
  94. #endif /* SDL_error_h_ */
  95. /* vi: set ts=4 sw=4 expandtab: */