src/SDL_log.c
changeset 5223 ab0d7cecc0f6
parent 5221 2ee8112bfc6b
child 5235 1e28342cb15d
equal deleted inserted replaced
5222:c66b2a778b7e 5223:ab0d7cecc0f6
   231 #endif /* __ANDROID__ */
   231 #endif /* __ANDROID__ */
   232 
   232 
   233 void
   233 void
   234 SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
   234 SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
   235 {
   235 {
   236     char message[SDL_MAX_LOG_MESSAGE];
   236     char *message;
   237 
   237 
   238     /* Make sure we don't exceed array bounds */
   238     /* Make sure we don't exceed array bounds */
   239     if (priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
   239     if (priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
   240         return;
   240         return;
   241     }
   241     }
   243     /* See if we want to do anything with this message */
   243     /* See if we want to do anything with this message */
   244     if (priority < SDL_LogGetPriority(category)) {
   244     if (priority < SDL_LogGetPriority(category)) {
   245         return;
   245         return;
   246     }
   246     }
   247 
   247 
   248     SDL_vsnprintf(message, SDL_arraysize(message), fmt, ap);
   248     message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
       
   249     if (!message) {
       
   250         return;
       
   251     }
       
   252     SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
   249 
   253 
   250 #if defined(__WIN32__)
   254 #if defined(__WIN32__)
       
   255     /* Way too many allocations here, urgh */
   251     {
   256     {
   252         char output[32+SDL_MAX_LOG_MESSAGE];
   257         char *output;
       
   258         size_t length;
   253         LPTSTR tstr;
   259         LPTSTR tstr;
   254 
   260 
   255         SDL_snprintf(output, SDL_arraysize(output), "%s: %s", SDL_priority_prefixes[priority], message);
   261         length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1;
       
   262         output = SDL_stack_alloc(char, length);
       
   263         SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message);
   256         tstr = WIN_UTF8ToString(output);
   264         tstr = WIN_UTF8ToString(output);
   257         OutputDebugString(tstr);
   265         OutputDebugString(tstr);
   258         SDL_free(tstr);
   266         SDL_free(tstr);
       
   267         SDL_stack_free(output);
   259     }
   268     }
   260 #elif defined(__ANDROID__)
   269 #elif defined(__ANDROID__)
   261     {
   270     {
   262         char tag[32];
   271         char tag[32];
   263 
   272 
   266     }
   275     }
   267 #endif
   276 #endif
   268 #if HAVE_STDIO_H
   277 #if HAVE_STDIO_H
   269     fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
   278     fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
   270 #endif
   279 #endif
       
   280     SDL_stack_free(message);
   271 }
   281 }
   272 
   282 
   273 /* vi: set ts=4 sw=4 expandtab: */
   283 /* vi: set ts=4 sw=4 expandtab: */