src/SDL_log.c
changeset 7344 3d9397262c10
parent 7343 faf0d8c7dbec
child 7350 302af2a46a66
equal deleted inserted replaced
7343:faf0d8c7dbec 7344:3d9397262c10
   264 
   264 
   265 void
   265 void
   266 SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
   266 SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
   267 {
   267 {
   268     char *message;
   268     char *message;
       
   269     size_t len;
   269 
   270 
   270     /* Nothing to do if we don't have an output function */
   271     /* Nothing to do if we don't have an output function */
   271     if (!SDL_log_function) {
   272     if (!SDL_log_function) {
   272         return;
   273         return;
   273     }
   274     }
   284 
   285 
   285     message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
   286     message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
   286     if (!message) {
   287     if (!message) {
   287         return;
   288         return;
   288     }
   289     }
       
   290 
   289     SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
   291     SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
       
   292 
       
   293     /* Chop off final endline. */
       
   294     len = SDL_strlen(message);
       
   295     if ((len > 0) && (message[len-1] == '\n')) {
       
   296         message[--len] = '\0';
       
   297         if ((len > 0) && (message[len-1] == '\r')) {  /* catch "\r\n", too. */
       
   298             message[--len] = '\0';
       
   299         }
       
   300     }
       
   301 
   290     SDL_log_function(SDL_log_userdata, category, priority, message);
   302     SDL_log_function(SDL_log_userdata, category, priority, message);
   291     SDL_stack_free(message);
   303     SDL_stack_free(message);
   292 }
   304 }
   293 
   305 
   294 #if defined(__WIN32__)
   306 #if defined(__WIN32__)
   388     {
   400     {
   389         unsigned int length;
   401         unsigned int length;
   390         char*        output;
   402         char*        output;
   391         FILE*        pFile;
   403         FILE*        pFile;
   392         /* !!! FIXME: is there any reason we didn't just use fprintf() here? */
   404         /* !!! FIXME: is there any reason we didn't just use fprintf() here? */
   393         length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1;
   405         length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 2;
   394         output = SDL_stack_alloc(char, length);
   406         output = SDL_stack_alloc(char, length);
   395         SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message);
   407         SDL_snprintf(output, length, "%s: %s\n", SDL_priority_prefixes[priority], message);
   396         pFile = fopen ("SDL_Log.txt", "a");
   408         pFile = fopen ("SDL_Log.txt", "a");
   397         fwrite (output, strlen (output), 1, pFile);
   409         fwrite (output, strlen (output), 1, pFile);
   398         SDL_stack_free(output);
   410         SDL_stack_free(output);
   399         fclose (pFile);
   411         fclose (pFile);
   400     }
   412     }