Added SDL_GetErrorMsg() to get the error message in a thread-safe way
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/include/SDL_error.h b/include/SDL_error.h
index aae37c0..962d62f 100644
--- a/include/SDL_error.h
+++ b/include/SDL_error.h
@@ -37,9 +37,45 @@ extern "C" {
#endif
/* Public functions */
-/* SDL_SetError() unconditionally returns -1. */
+
+
+/**
+ * \brief Set the error message for the current thread
+ *
+ * \return -1, there is no error handling for this function
+ */
extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/**
+ * \brief Get the last error message that was set
+ *
+ * SDL API functions may set error messages and then succeed, so you should
+ * only use the error value if a function fails.
+ *
+ * This returns a pointer to a static buffer for convenience and should not
+ * be called by multiple threads simultaneously.
+ *
+ * \return a pointer to the last error message that was set
+ */
extern DECLSPEC const char *SDLCALL SDL_GetError(void);
+
+/**
+ * \brief Get the last error message that was set for the current thread
+ *
+ * SDL API functions may set error messages and then succeed, so you should
+ * only use the error value if a function fails.
+ *
+ * \param errstr A buffer to fill with the last error message that was set
+ * for the current thread
+ * \param maxlen The size of the buffer pointed to by the errstr parameter
+ *
+ * \return errstr
+ */
+extern DECLSPEC char * SDLCALL SDL_GetErrorMsg(char *errstr, int maxlen);
+
+/**
+ * \brief Clear the error message for the current thread
+ */
extern DECLSPEC void SDLCALL SDL_ClearError(void);
/**
diff --git a/src/SDL_error.c b/src/SDL_error.c
index 36f8003..bf17087 100644
--- a/src/SDL_error.c
+++ b/src/SDL_error.c
@@ -39,8 +39,6 @@ SDL_LookupString(const char *key)
/* Public functions */
-static char *SDL_GetErrorMsg(char *errstr, int maxlen);
-
int
SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
@@ -192,7 +190,7 @@ main(int argc, char *argv[])
/* This function has a bit more overhead than most error functions
so that it supports internationalization and thread-safe errors.
*/
-static char *
+char *
SDL_GetErrorMsg(char *errstr, int maxlen)
{
SDL_error *error;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index d6476a2..e2a44b0 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -756,3 +756,4 @@
#define SDL_JoystickSetVirtualBall SDL_JoystickSetVirtualBall_REAL
#define SDL_JoystickSetVirtualButton SDL_JoystickSetVirtualButton_REAL
#define SDL_JoystickSetVirtualHat SDL_JoystickSetVirtualHat_REAL
+#define SDL_GetErrorMsg SDL_GetErrorMsg_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 2d8a291..160ac76 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -816,3 +816,4 @@ SDL_DYNAPI_PROC(int,SDL_JoystickSetVirtualAxis,(SDL_Joystick *a, int b, Sint16 c
SDL_DYNAPI_PROC(int,SDL_JoystickSetVirtualBall,(SDL_Joystick *a, int b, Sint16 c, Sint16 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_JoystickSetVirtualButton,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_JoystickSetVirtualHat,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
+SDL_DYNAPI_PROC(char*,SDL_GetErrorMsg,(char *a, int b),(a,b),return)