19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Simple error handling in SDL */
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_error.h"
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_error_c.h"
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Routine to get the thread-specific error variable */
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_THREADS_DISABLED
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The  SDL_arraysize(The ),default (non-thread-safe) global error variable */
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_error SDL_global_error;
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_GetErrBuf()	(&SDL_global_error)
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern SDL_error *SDL_GetErrBuf(void);
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* SDL_THREADS_DISABLED */
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_ERRBUFIZE	1024
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Private functions */
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic const char *SDL_LookupString(const char *key)
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* FIXME: Add code to lookup key in language string hash-table */
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return key;
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Public functions */
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_SetError (const char *fmt, ...)
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	va_list ap;
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_error *error;
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Copy in the key, mark error as valid */
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	error = SDL_GetErrBuf();
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	error->error = 1;
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_strlcpy((char *)error->key, fmt, sizeof(error->key));
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	va_start(ap, fmt);
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	error->argc = 0;
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	while ( *fmt ) {
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( *fmt++ == '%' ) {
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				++fmt;
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			switch (*fmt++) {
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 0:  /* Malformed format string.. */
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				--fmt;
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'c':
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'i':
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'd':
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'u':
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'o':
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'x':
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'X':
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				error->args[error->argc++].value_i =
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall							va_arg(ap, int);
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'f':
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				error->args[error->argc++].value_f =
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall							va_arg(ap, double);
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 'p':
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				error->args[error->argc++].value_ptr =
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall							va_arg(ap, void *);
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    case 's':
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				{
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  int i = error->argc;
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  const char *str = va_arg(ap, const char *);
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  if (str == NULL)
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				      str = "(null)";
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  SDL_strlcpy((char *)error->args[i].buf, str, ERR_MAX_STRLEN);
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  error->argc++;
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    default:
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( error->argc >= ERR_MAX_ARGS ) {
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	va_end(ap);
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* If we are in debug mode, print out an error message */
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef DEBUG_ERROR
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This function has a bit more overhead than most error functions
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   so that it supports internationalization and thread-safe errors.
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallchar *SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_error *error;
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Clear the error string */
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	*errstr = '\0'; --maxlen;
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Get the thread-safe error, and print it out */
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	error = SDL_GetErrBuf();
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( error->error ) {
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		const char *fmt;
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		char *msg = errstr;
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		int len;
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		int argi;
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		fmt = SDL_LookupString(error->key);
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		argi = 0;
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		while ( *fmt && (maxlen > 0) ) {
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( *fmt == '%' ) {
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				char tmp[32], *spot = tmp;
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				*spot++ = *fmt++;
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				while ( (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) && spot < (tmp+SDL_arraysize(tmp)-2) ) {
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					*spot++ = *fmt++;
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				*spot++ = *fmt++;
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				*spot++ = '\0';
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				switch (spot[-2]) {
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				    case '%':
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					*msg++ = '%';
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					maxlen -= 1;
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					break;
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				    case 'c':
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				    case 'i':
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			            case 'd':
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			            case 'u':
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			            case 'o':
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				    case 'x':
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				    case 'X':
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_i);
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					msg += len;
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					maxlen -= len;
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					break;
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				    case 'f':
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_f);
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					msg += len;
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					maxlen -= len;
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					break;
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				    case 'p':
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_ptr);
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					msg += len;
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					maxlen -= len;
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					break;
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				    case 's':
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					len = SDL_snprintf(msg, maxlen, tmp, SDL_LookupString(error->args[argi++].buf));
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					msg += len;
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					maxlen -= len;
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					break;
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			} else {
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				*msg++ = *fmt++;
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				maxlen -= 1;
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		*msg = 0;	/* NULL terminate the string */
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(errstr);
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Available for backwards compatibility */
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallchar *SDL_GetError (void)
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	static char errmsg[SDL_ERRBUFIZE];
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return((char *)SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE));
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_ClearError(void)
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_error *error;
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	error = SDL_GetErrBuf();
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	error->error = 0;
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Very common errors go here */
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_Error(SDL_errorcode code)
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	switch (code) {
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case SDL_ENOMEM:
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_SetError("Out of memory");
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case SDL_EFREAD:
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_SetError("Error reading from datastream");
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case SDL_EFWRITE:
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_SetError("Error writing to datastream");
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case SDL_EFSEEK:
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_SetError("Error seeking in datastream");
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		default:
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_SetError("Unknown SDL error");
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef TEST_ERROR
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint main(int argc, char *argv[])
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	char buffer[BUFSIZ+1];
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_SetError("Hi there!");
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Error 1: %s\n", SDL_GetError());
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_ClearError();
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_memset(buffer, '1', BUFSIZ);
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	buffer[BUFSIZ] = 0;
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Error 2: %s\n", SDL_GetError());
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	exit(0);
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
239