Forráskód Böngészése

Added formatting to error string.

Camilla Berglund 13 éve
szülő
commit
ba941b2fc8
2 módosított fájl, 25 hozzáadás és 3 törlés
  1. 24 2
      src/error.c
  2. 1 1
      src/internal.h

+ 24 - 2
src/error.c

@@ -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);

+ 1 - 1
src/internal.h

@@ -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);