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

§ SDL_OutOfMemory

§ SDL_Unsupported

#define SDL_Unsupported ( )    SDL_Error(SDL_UNSUPPORTED)

Definition at line 53 of file SDL_error.h.

Referenced by SDL_AudioOpenDevice_Default(), SDL_BlendFillRect_RGB(), SDL_BlendFillRect_RGBA(), SDL_BlendPoint_RGB(), SDL_BlendPoint_RGBA(), SDL_CaptureMouse(), SDL_CreateWindowFrom(), SDL_DINPUT_HapticGetEffectStatus(), SDL_DINPUT_HapticNewEffect(), SDL_DINPUT_HapticOpen(), SDL_DINPUT_HapticOpenFromJoystick(), SDL_DINPUT_HapticPause(), SDL_DINPUT_HapticRunEffect(), SDL_DINPUT_HapticSetAutocenter(), SDL_DINPUT_HapticSetGain(), SDL_DINPUT_HapticStopAll(), SDL_DINPUT_HapticStopEffect(), SDL_DINPUT_HapticUnpause(), SDL_DINPUT_HapticUpdateEffect(), SDL_DINPUT_JoystickOpen(), SDL_DINPUT_JoystickSameHaptic(), SDL_DINPUT_MaybeAddDevice(), SDL_DINPUT_MaybeRemoveDevice(), SDL_DrawPoint(), SDL_DrawPoints(), SDL_GetDisplayDPI(), SDL_GetWindowBordersSize(), SDL_GetWindowWMInfo(), SDL_GL_BindTexture(), SDL_GL_GetAttribute(), SDL_GL_SetAttribute(), SDL_GL_UnbindTexture(), SDL_RenderReadPixels(), SDL_SetRenderTarget(), SDL_SetSurfaceBlendMode(), SDL_SetWindowGammaRamp(), SDL_SetWindowHitTest(), SDL_SetWindowInputFocus(), SDL_SetWindowModalFor(), SDL_SetWindowOpacity(), SDL_UpdateYUVTexture(), SDL_WarpMouseGlobal(), SDL_XINPUT_HapticGetEffectStatus(), SDL_XINPUT_HapticNewEffect(), SDL_XINPUT_HapticOpen(), SDL_XINPUT_HapticOpenFromJoystick(), SDL_XINPUT_HapticPause(), SDL_XINPUT_HapticRunEffect(), SDL_XINPUT_HapticSetAutocenter(), SDL_XINPUT_HapticSetGain(), SDL_XINPUT_HapticStopAll(), SDL_XINPUT_HapticStopEffect(), SDL_XINPUT_HapticUnpause(), SDL_XINPUT_HapticUpdateEffect(), SDL_XINPUT_JoystickOpen(), SDL_XINPUT_JoystickSameHaptic(), SDL_XINPUT_MaybeAddDevice(), SDL_XINPUT_MaybeRemoveDevice(), SDLTest_GenerateSignedBoundaryValues(), and SDLTest_GenerateUnsignedBoundaryValues().

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.

Function Documentation

§ SDL_ClearError()

void SDL_ClearError ( void  )

Definition at line 237 of file SDL_error.c.

References SDL_error::error, and SDL_GetErrBuf().

Referenced by SDL_Error().

238 {
239  SDL_error *error;
240 
241  error = SDL_GetErrBuf();
242  error->error = 0;
243 }
SDL_error * SDL_GetErrBuf(void)
Definition: SDL_thread.c:206

§ SDL_Error()

int SDL_Error ( SDL_errorcode  code)

Definition at line 247 of file SDL_error.c.

References main, SDL_ClearError(), SDL_EFREAD, SDL_EFSEEK, SDL_EFWRITE, SDL_ENOMEM, SDL_GetError(), SDL_memset, SDL_SetError(), and SDL_UNSUPPORTED.

248 {
249  switch (code) {
250  case SDL_ENOMEM:
251  return SDL_SetError("Out of memory");
252  case SDL_EFREAD:
253  return SDL_SetError("Error reading from datastream");
254  case SDL_EFWRITE:
255  return SDL_SetError("Error writing to datastream");
256  case SDL_EFSEEK:
257  return SDL_SetError("Error seeking in datastream");
258  case SDL_UNSUPPORTED:
259  return SDL_SetError("That operation is not supported");
260  default:
261  return SDL_SetError("Unknown SDL error");
262  }
263 }
int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Definition: SDL_error.c:53

§ SDL_GetError()

const char* SDL_GetError ( void  )

Definition at line 229 of file SDL_error.c.

References SDL_ERRBUFIZE, and SDL_GetErrorMsg().

Referenced by SDL_Error(), and SDL_SetError().

230 {
231  static char errmsg[SDL_ERRBUFIZE];
232 
233  return SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE);
234 }
#define SDL_ERRBUFIZE
Definition: SDL_error.c:39
static char * SDL_GetErrorMsg(char *errstr, int maxlen)
Definition: SDL_error.c:127

§ SDL_SetError()

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

Definition at line 53 of file SDL_error.c.

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_GetErrBuf(), SDL_GetError(), SDL_LOG_CATEGORY_ERROR, SDL_LogDebug, SDL_strlcpy, SDL_error::value_f, SDL_error::value_i, and SDL_error::value_ptr.

Referenced by SDL_Error().

54 {
55  va_list ap;
56  SDL_error *error;
57 
58  /* Ignore call if invalid format pointer was passed */
59  if (fmt == NULL) return -1;
60 
61  /* Copy in the key, mark error as valid */
62  error = SDL_GetErrBuf();
63  error->error = 1;
64  SDL_strlcpy((char *) error->key, fmt, sizeof(error->key));
65 
66  va_start(ap, fmt);
67  error->argc = 0;
68  while (*fmt) {
69  if (*fmt++ == '%') {
70  while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
71  ++fmt;
72  }
73  switch (*fmt++) {
74  case 0: /* Malformed format string.. */
75  --fmt;
76  break;
77  case 'c':
78  case 'i':
79  case 'd':
80  case 'u':
81  case 'o':
82  case 'x':
83  case 'X':
84  error->args[error->argc++].value_i = va_arg(ap, int);
85  break;
86  case 'f':
87  error->args[error->argc++].value_f = va_arg(ap, double);
88  break;
89  case 'p':
90  error->args[error->argc++].value_ptr = va_arg(ap, void *);
91  break;
92  case 's':
93  {
94  int i = error->argc;
95  const char *str = va_arg(ap, const char *);
96  if (str == NULL)
97  str = "(null)";
98  SDL_strlcpy((char *) error->args[i].buf, str,
100  error->argc++;
101  }
102  break;
103  default:
104  break;
105  }
106  if (error->argc >= ERR_MAX_ARGS) {
107  break;
108  }
109  }
110  }
111  va_end(ap);
112 
113  /* If we are in debug mode, print out an error message */
115 
116  return -1;
117 }
#define SDL_strlcpy
double value_f
Definition: SDL_error_c.h:54
SDL_error * SDL_GetErrBuf(void)
Definition: SDL_thread.c:206
#define ERR_MAX_STRLEN
Definition: SDL_error_c.h:30
const char * SDL_GetError(void)
Definition: SDL_error.c:229
#define SDL_LogDebug
union SDL_error::@23 args[ERR_MAX_ARGS]
#define ERR_MAX_ARGS
Definition: SDL_error_c.h:31
char key[ERR_MAX_STRLEN]
Definition: SDL_error_c.h:43
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
#define NULL
Definition: begin_code.h:143
char buf[ERR_MAX_STRLEN]
Definition: SDL_error_c.h:55
void * value_ptr
Definition: SDL_error_c.h:49
int value_i
Definition: SDL_error_c.h:53