/* This function has a bit more overhead than most error functions so that it supports internationalization and thread-safe errors. */ Uint16 *SDL_GetErrorMsgUNICODE(Uint16 *errstr, unsigned int maxlen) { SDL_error *error; /* Clear the error string */ *errstr = 0; --maxlen; /* Get the thread-safe error, and print it out */ error = SDL_GetErrBuf(); if ( error->error ) { Uint16 translated[ERR_MAX_STRLEN], *fmt, *msg; int len; int argi; /* Print out the UNICODE error message */ SDL_LookupString(error->key, translated, sizeof(translated)); msg = errstr; argi = 0; for ( fmt=translated; *fmt && (maxlen > 0); ) { if ( *fmt == '%' ) { switch (fmt[1]) { case 'S': /* Special SKIP operand */ argi += (fmt[2] - '0'); ++fmt; break; case '%': *msg++ = '%'; maxlen -= 1; break; #if 0 /* What is a character anyway? (UNICODE issues) */ case 'c': *msg++ = (unsigned char) error->args[argi++].value_c; maxlen -= 1; break; #endif case 'd': len = PrintInt(msg, maxlen, error->args[argi++].value_i); msg += len; maxlen -= len; break; case 'f': len = PrintDouble(msg, maxlen, error->args[argi++].value_f); msg += len; maxlen -= len; break; case 'p': len = PrintPointer(msg, maxlen, error->args[argi++].value_ptr); msg += len; maxlen -= len; break; case 's': /* UNICODE string */ { Uint16 buf[ERR_MAX_STRLEN], *str; SDL_LookupString(error->args[argi++].buf, buf, sizeof(buf)); str = buf; while ( *str && (maxlen > 0) ) { *msg++ = *str++; maxlen -= 1; } } break; } fmt += 2; } else { *msg++ = *fmt++; maxlen -= 1; } } *msg = 0; /* NULL terminate the string */ } return(errstr); }
/* This function has a bit more overhead than most error functions so that it supports internationalization and thread-safe errors. */ char *SDL_GetErrorMsg(char *errstr, unsigned int maxlen) { SDL_error *error; /* Clear the error string */ *errstr = '\0'; --maxlen; /* Get the thread-safe error, and print it out */ error = SDL_GetErrBuf(); if ( error->error ) { const char *fmt; char *msg = errstr; int len; int argi; fmt = SDL_LookupString(error->key); argi = 0; while ( *fmt && (maxlen > 0) ) { if ( *fmt == '%' ) { char tmp[32], *spot = tmp; *spot++ = *fmt++; while ( (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) && spot < (tmp+SDL_arraysize(tmp)-2) ) { *spot++ = *fmt++; } *spot++ = *fmt++; *spot++ = '\0'; switch (spot[-2]) { case '%': *msg++ = '%'; maxlen -= 1; break; case 'c': case 'i': case 'd': case 'u': case 'o': case 'x': case 'X': len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_i); msg += len; maxlen -= len; break; case 'f': len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_f); msg += len; maxlen -= len; break; case 'p': len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_ptr); msg += len; maxlen -= len; break; case 's': len = SDL_snprintf(msg, maxlen, tmp, SDL_LookupString(error->args[argi++].buf)); msg += len; maxlen -= len; break; } } else { *msg++ = *fmt++; maxlen -= 1; } } *msg = 0; /* NULL terminate the string */ } return(errstr); }