SDL  2.0
SDL_error.h File Reference
#include "SDL_stdinc.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_error.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int SDL_SetError (SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
 
const char * SDL_GetError (void)
 
void SDL_ClearError (void)
 

Internal error functions

Private error reporting function - used internally.

#define SDL_OutOfMemory()   SDL_Error(SDL_ENOMEM)
 
#define SDL_Unsupported()   SDL_Error(SDL_UNSUPPORTED)
 
#define SDL_InvalidParamError(param)   SDL_SetError("Parameter '%s' is invalid", (param))
 
enum  SDL_errorcode {
  SDL_ENOMEM,
  SDL_EFREAD,
  SDL_EFWRITE,
  SDL_EFSEEK,
  SDL_UNSUPPORTED,
  SDL_LASTERROR
}
 
int SDL_Error (SDL_errorcode code)
 

Detailed Description

Simple error message routines for SDL.

Definition in file SDL_error.h.

Macro Definition Documentation

◆ SDL_InvalidParamError

#define SDL_InvalidParamError (   param)    SDL_SetError("Parameter '%s' is invalid", (param))

Definition at line 54 of file SDL_error.h.

◆ SDL_OutOfMemory

#define SDL_OutOfMemory ( )    SDL_Error(SDL_ENOMEM)

Definition at line 52 of file SDL_error.h.

◆ SDL_Unsupported

#define SDL_Unsupported ( )    SDL_Error(SDL_UNSUPPORTED)

Definition at line 53 of file SDL_error.h.

Enumeration Type Documentation

◆ SDL_errorcode

Enumerator
SDL_ENOMEM 
SDL_EFREAD 
SDL_EFWRITE 
SDL_EFSEEK 
SDL_UNSUPPORTED 
SDL_LASTERROR 

Definition at line 55 of file SDL_error.h.

56 {
57  SDL_ENOMEM,
58  SDL_EFREAD,
60  SDL_EFSEEK,

Function Documentation

◆ SDL_ClearError()

void SDL_ClearError ( void  )

Definition at line 145 of file SDL_dynapi_procs.h.

References SDL_error::error, and SDL_GetErrBuf().

◆ SDL_Error()

int SDL_Error ( SDL_errorcode  code)

Definition at line 158 of file SDL_error.c.

159 {
160  switch (code) {
161  case SDL_ENOMEM:
162  return SDL_SetError("Out of memory");
163  case SDL_EFREAD:
164  return SDL_SetError("Error reading from datastream");
165  case SDL_EFWRITE:
166  return SDL_SetError("Error writing to datastream");
167  case SDL_EFSEEK:
168  return SDL_SetError("Error seeking in datastream");
169  case SDL_UNSUPPORTED:
170  return SDL_SetError("That operation is not supported");
171  default:
172  return SDL_SetError("Unknown SDL error");
173  }
174 }

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

◆ SDL_GetError()

const char* SDL_GetError ( void  )

Definition at line 140 of file SDL_error.c.

141 {
142  static char errmsg[SDL_ERRBUFIZE];
143 
144  return SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE);
145 }

References SDL_ERRBUFIZE, and SDL_GetErrorMsg().

◆ SDL_SetError()

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

Definition at line 55 of file SDL_error.c.

56 {
57  va_list ap;
58  SDL_error *error;
59 
60  /* Ignore call if invalid format pointer was passed */
61  if (fmt == NULL) return -1;
62 
63  /* Copy in the key, mark error as valid */
64  error = SDL_GetErrBuf();
65  error->error = 1;
66  SDL_strlcpy((char *) error->key, fmt, sizeof(error->key));
67 
68  va_start(ap, fmt);
69  error->argc = 0;
70  while (*fmt) {
71  if (*fmt++ == '%') {
72  while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
73  ++fmt;
74  }
75  switch (*fmt++) {
76  case 0: /* Malformed format string.. */
77  --fmt;
78  break;
79  case 'l':
80  switch (*fmt++) {
81  case 0: /* Malformed format string.. */
82  --fmt;
83  break;
84  case 'i': case 'd': case 'u': case 'x': case 'X':
85  error->args[error->argc++].value_l = va_arg(ap, long);
86  break;
87  }
88  break;
89  case 'c':
90  case 'i':
91  case 'd':
92  case 'u':
93  case 'o':
94  case 'x':
95  case 'X':
96  error->args[error->argc++].value_i = va_arg(ap, int);
97  break;
98  case 'f':
99  error->args[error->argc++].value_f = va_arg(ap, double);
100  break;
101  case 'p':
102  error->args[error->argc++].value_ptr = va_arg(ap, void *);
103  break;
104  case 's':
105  {
106  int i = error->argc;
107  const char *str = va_arg(ap, const char *);
108  if (str == NULL)
109  str = "(null)";
110  SDL_strlcpy((char *) error->args[i].buf, str,
112  error->argc++;
113  }
114  break;
115  default:
116  break;
117  }
118  if (error->argc >= ERR_MAX_ARGS) {
119  break;
120  }
121  }
122  }
123  va_end(ap);
124 
126  /* If we are in debug mode, print out an error message
127  * Avoid stomping on the static buffer in GetError, just
128  * in case this is called while processing a ShowMessageBox to
129  * show an error already in that static buffer.
130  */
131  char errmsg[SDL_ERRBUFIZE];
132  SDL_GetErrorMsg(errmsg, sizeof(errmsg));
133  SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", errmsg);
134  }
135  return -1;
136 }

References SDL_error::argc, SDL_error::args, SDL_error::buf, ERR_MAX_ARGS, ERR_MAX_STRLEN, SDL_error::error, i, SDL_error::key, NULL, SDL_ERRBUFIZE, SDL_GetErrBuf(), SDL_GetErrorMsg(), SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_DEBUG, SDL_LogDebug, SDL_LogGetPriority, SDL_strlcpy, SDL_error::value_f, SDL_error::value_i, SDL_error::value_l, and SDL_error::value_ptr.

Referenced by SDL_Error().

SDL_ERRBUFIZE
#define SDL_ERRBUFIZE
Definition: SDL_error.c:39
SDL_strlcpy
#define SDL_strlcpy
Definition: SDL_dynapi_overrides.h:394
NULL
#define NULL
Definition: begin_code.h:167
SDL_error::value_ptr
void * value_ptr
Definition: SDL_error_c.h:49
SDL_error::value_l
long value_l
Definition: SDL_error_c.h:54
SDL_error::key
char key[ERR_MAX_STRLEN]
Definition: SDL_error_c.h:43
SDL_errorcode
SDL_errorcode
Definition: SDL_error.h:55
SDL_ENOMEM
@ SDL_ENOMEM
Definition: SDL_error.h:57
SDL_error::args
union SDL_error::@35 args[ERR_MAX_ARGS]
SDL_error
Definition: SDL_error_c.h:33
SDL_LogGetPriority
#define SDL_LogGetPriority
Definition: SDL_dynapi_overrides.h:237
SDL_LOG_PRIORITY_DEBUG
@ SDL_LOG_PRIORITY_DEBUG
Definition: SDL_log.h:105
SDL_GetErrBuf
SDL_error * SDL_GetErrBuf(void)
Definition: SDL_thread.c:206
ERR_MAX_ARGS
#define ERR_MAX_ARGS
Definition: SDL_error_c.h:31
SDL_error::value_f
double value_f
Definition: SDL_error_c.h:55
SDL_LOG_CATEGORY_ERROR
@ SDL_LOG_CATEGORY_ERROR
Definition: SDL_log.h:67
SDL_LogDebug
#define SDL_LogDebug
Definition: SDL_dynapi_overrides.h:33
SDL_error::argc
int argc
Definition: SDL_error_c.h:46
SDL_error::error
int error
Definition: SDL_error_c.h:36
SDL_error::value_i
int value_i
Definition: SDL_error_c.h:53
ERR_MAX_STRLEN
#define ERR_MAX_STRLEN
Definition: SDL_error_c.h:30
SDL_LASTERROR
@ SDL_LASTERROR
Definition: SDL_error.h:62
SDL_SetError
int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Definition: SDL_error.c:55
SDL_error::buf
char buf[ERR_MAX_STRLEN]
Definition: SDL_error_c.h:56
SDL_UNSUPPORTED
@ SDL_UNSUPPORTED
Definition: SDL_error.h:61
SDL_EFSEEK
@ SDL_EFSEEK
Definition: SDL_error.h:60
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_GetErrorMsg
static char * SDL_GetErrorMsg(char *errstr, int maxlen)
Definition: SDL_error.c:206
SDL_EFWRITE
@ SDL_EFWRITE
Definition: SDL_error.h:59
SDL_EFREAD
@ SDL_EFREAD
Definition: SDL_error.h:58