Added formatting to error string.

This commit is contained in:
Camilla Berglund 2012-08-02 15:13:57 +02:00
parent 208377d08e
commit ba941b2fc8
2 changed files with 25 additions and 3 deletions

View File

@ -29,6 +29,9 @@
#include "internal.h"
#include <stdio.h>
#include <stdarg.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
@ -49,11 +52,30 @@ static GLFWerrorfun _glfwErrorCallback = NULL;
// This function may be called without GLFW having been initialized
//========================================================================
void _glfwSetError(int error, const char* description)
void _glfwSetError(int error, const char* format, ...)
{
if (_glfwErrorCallback)
{
if (!description)
char buffer[16384];
const char* description;
// We would use vasprintf here if msvcrt supported it
if (format)
{
int count;
va_list vl;
va_start(vl, format);
count = vsnprintf(buffer, sizeof(buffer), format, vl);
va_end(vl);
if (count < 0)
buffer[sizeof(buffer) - 1] = '\0';
description = buffer;
}
else
description = glfwErrorString(error);
_glfwErrorCallback(error, description);

View File

@ -338,7 +338,7 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
// Error handling (error.c)
void _glfwSetError(int error, const char* description);
void _glfwSetError(int error, const char* format, ...);
// Window management (window.c)
void _glfwSetDefaultWindowHints(void);