SDL  2.0
SDL_error.c File Reference
#include "./SDL_internal.h"
#include "SDL_error.h"
#include "SDL_error_c.h"
+ Include dependency graph for SDL_error.c:

Go to the source code of this file.

Macros

#define SDL_ERRBUFIZE   1024
 

Functions

int SDL_SetError (SDL_PRINTF_FORMAT_STRING const char *fmt,...)
 Set the error message for the current thread. More...
 
const char * SDL_GetError (void)
 Get the last error message that was set. More...
 
void SDL_ClearError (void)
 Clear the error message for the current thread. More...
 
int SDL_Error (SDL_errorcode code)
 
char * SDL_GetErrorMsg (char *errstr, int maxlen)
 Get the last error message that was set for the current thread. More...
 

Macro Definition Documentation

◆ SDL_ERRBUFIZE

#define SDL_ERRBUFIZE   1024

Definition at line 28 of file SDL_error.c.

Function Documentation

◆ SDL_ClearError()

void SDL_ClearError ( void  )

Clear the error message for the current thread.

Definition at line 62 of file SDL_error.c.

63 {
64  SDL_GetErrBuf()->error = 0;
65 }
SDL_error * SDL_GetErrBuf(void)
Definition: SDL_thread.c:205

References SDL_error::error, and SDL_GetErrBuf().

◆ SDL_Error()

int SDL_Error ( SDL_errorcode  code)

Definition at line 69 of file SDL_error.c.

70 {
71  switch (code) {
72  case SDL_ENOMEM:
73  return SDL_SetError("Out of memory");
74  case SDL_EFREAD:
75  return SDL_SetError("Error reading from datastream");
76  case SDL_EFWRITE:
77  return SDL_SetError("Error writing to datastream");
78  case SDL_EFSEEK:
79  return SDL_SetError("Error seeking in datastream");
80  case SDL_UNSUPPORTED:
81  return SDL_SetError("That operation is not supported");
82  default:
83  return SDL_SetError("Unknown SDL error");
84  }
85 }
int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Set the error message for the current thread.
Definition: SDL_error.c:31
@ SDL_EFSEEK
Definition: SDL_error.h:96
@ SDL_EFWRITE
Definition: SDL_error.h:95
@ SDL_UNSUPPORTED
Definition: SDL_error.h:97
@ SDL_EFREAD
Definition: SDL_error.h:94
@ SDL_ENOMEM
Definition: SDL_error.h:93

References SDL_EFREAD, SDL_EFSEEK, SDL_EFWRITE, SDL_ENOMEM, SDL_SetError(), and SDL_UNSUPPORTED.

◆ SDL_GetError()

const char* SDL_GetError ( void  )

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.

Returns
a pointer to the last error message that was set

Definition at line 55 of file SDL_error.c.

56 {
57  const SDL_error *error = SDL_GetErrBuf();
58  return error->error ? error->str : "";
59 }
char str[ERR_MAX_STRLEN]
Definition: SDL_error_c.h:35

References SDL_error::error, SDL_GetErrBuf(), and SDL_error::str.

◆ SDL_GetErrorMsg()

char* SDL_GetErrorMsg ( char *  errstr,
int  maxlen 
)

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.

Parameters
errstrA buffer to fill with the last error message that was set for the current thread
maxlenThe size of the buffer pointed to by the errstr parameter
Returns
errstr

Definition at line 106 of file SDL_error.c.

107 {
108  const SDL_error *error = SDL_GetErrBuf();
109 
110  if (error->error) {
111  SDL_strlcpy(errstr, error->str, maxlen);
112  } else {
113  *errstr = '\0';
114  }
115 
116  return errstr;
117 }
#define SDL_strlcpy

References SDL_error::error, SDL_GetErrBuf(), SDL_strlcpy, and SDL_error::str.

◆ SDL_SetError()

int SDL_SetError ( SDL_PRINTF_FORMAT_STRING const char *  fmt,
  ... 
)

Set the error message for the current thread.

Returns
-1, there is no error handling for this function

Definition at line 31 of file SDL_error.c.

32 {
33  /* Ignore call if invalid format pointer was passed */
34  if (fmt != NULL) {
35  va_list ap;
36  SDL_error *error = SDL_GetErrBuf();
37 
38  error->error = 1; /* mark error as valid */
39 
40  va_start(ap, fmt);
41  SDL_vsnprintf(error->str, ERR_MAX_STRLEN, fmt, ap);
42  va_end(ap);
43 
45  /* If we are in debug mode, print out the error message */
47  }
48  }
49 
50  return -1;
51 }
#define SDL_LogGetPriority
#define SDL_vsnprintf
#define SDL_LogDebug
#define ERR_MAX_STRLEN
Definition: SDL_error_c.h:30
@ SDL_LOG_PRIORITY_DEBUG
Definition: SDL_log.h:105
@ SDL_LOG_CATEGORY_ERROR
Definition: SDL_log.h:67
#define NULL
Definition: begin_code.h:163

References ERR_MAX_STRLEN, SDL_error::error, NULL, SDL_GetErrBuf(), SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_DEBUG, SDL_LogDebug, SDL_LogGetPriority, SDL_vsnprintf, and SDL_error::str.

Referenced by SDL_Error().