src/SDL_error.c
changeset 7037 3fedf1f25b94
parent 6885 700f1b25f77f
child 7191 75360622e65f
equal deleted inserted replaced
7036:8c891504e325 7037:3fedf1f25b94
    47     return key;
    47     return key;
    48 }
    48 }
    49 
    49 
    50 /* Public functions */
    50 /* Public functions */
    51 
    51 
    52 void
    52 int
    53 SDL_SetError(const char *fmt, ...)
    53 SDL_SetError(const char *fmt, ...)
    54 {
    54 {
    55     va_list ap;
    55     va_list ap;
    56     SDL_error *error;
    56     SDL_error *error;
    57 
    57 
    58     /* Ignore call if invalid format pointer was passed */
    58     /* Ignore call if invalid format pointer was passed */
    59     if (fmt == NULL) return;
    59     if (fmt == NULL) return -1;
    60     
    60     
    61     /* Copy in the key, mark error as valid */
    61     /* Copy in the key, mark error as valid */
    62     error = SDL_GetErrBuf();
    62     error = SDL_GetErrBuf();
    63     error->error = 1;
    63     error->error = 1;
    64     SDL_strlcpy((char *) error->key, fmt, sizeof(error->key));
    64     SDL_strlcpy((char *) error->key, fmt, sizeof(error->key));
   110     }
   110     }
   111     va_end(ap);
   111     va_end(ap);
   112 
   112 
   113     /* If we are in debug mode, print out an error message */
   113     /* If we are in debug mode, print out an error message */
   114     SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError());
   114     SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError());
       
   115 
       
   116     return -1;
   115 }
   117 }
   116 
   118 
   117 /* This function has a bit more overhead than most error functions
   119 /* This function has a bit more overhead than most error functions
   118    so that it supports internationalization and thread-safe errors.
   120    so that it supports internationalization and thread-safe errors.
   119 */
   121 */
   214     error = SDL_GetErrBuf();
   216     error = SDL_GetErrBuf();
   215     error->error = 0;
   217     error->error = 0;
   216 }
   218 }
   217 
   219 
   218 /* Very common errors go here */
   220 /* Very common errors go here */
   219 void
   221 int
   220 SDL_Error(SDL_errorcode code)
   222 SDL_Error(SDL_errorcode code)
   221 {
   223 {
   222     switch (code) {
   224     switch (code) {
   223     case SDL_ENOMEM:
   225     case SDL_ENOMEM:
   224         SDL_SetError("Out of memory");
   226         return SDL_SetError("Out of memory");
   225         break;
       
   226     case SDL_EFREAD:
   227     case SDL_EFREAD:
   227         SDL_SetError("Error reading from datastream");
   228         return SDL_SetError("Error reading from datastream");
   228         break;
       
   229     case SDL_EFWRITE:
   229     case SDL_EFWRITE:
   230         SDL_SetError("Error writing to datastream");
   230         return SDL_SetError("Error writing to datastream");
   231         break;
       
   232     case SDL_EFSEEK:
   231     case SDL_EFSEEK:
   233         SDL_SetError("Error seeking in datastream");
   232         return SDL_SetError("Error seeking in datastream");
   234         break;
       
   235     case SDL_UNSUPPORTED:
   233     case SDL_UNSUPPORTED:
   236         SDL_SetError("That operation is not supported");
   234         return SDL_SetError("That operation is not supported");
   237         break;
       
   238     default:
   235     default:
   239         SDL_SetError("Unknown SDL error");
   236         return SDL_SetError("Unknown SDL error");
   240         break;
       
   241     }
   237     }
   242 }
   238 }
   243 
   239 
   244 #ifdef TEST_ERROR
   240 #ifdef TEST_ERROR
   245 int
   241 int