void SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap) { char *message; /* Nothing to do if we don't have an output function */ if (!SDL_log_function) { return; } /* Make sure we don't exceed array bounds */ if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) { return; } /* See if we want to do anything with this message */ if (priority < SDL_LogGetPriority(category)) { return; } message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); if (!message) { return; } SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap); SDL_log_function(SDL_log_userdata, category, priority, message); SDL_stack_free(message); }
void SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap) { char *message; size_t len; /* Nothing to do if we don't have an output function */ if (!SDL_log_function) { return; } /* Make sure we don't exceed array bounds */ if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) { return; } /* See if we want to do anything with this message */ if (priority < SDL_LogGetPriority(category)) { return; } /* !!! FIXME: why not just "char message[SDL_MAX_LOG_MESSAGE];" ? */ message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); if (!message) { return; } SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap); /* Chop off final endline. */ len = SDL_strlen(message); if ((len > 0) && (message[len-1] == '\n')) { message[--len] = '\0'; if ((len > 0) && (message[len-1] == '\r')) { /* catch "\r\n", too. */ message[--len] = '\0'; } } SDL_log_function(SDL_log_userdata, category, priority, message); SDL_stack_free(message); }