ucx/logging.c

changeset 39
3e55bed345f9
parent 17
11dffb40cd91
child 70
88092b88ec00
--- a/ucx/logging.c	Tue Sep 03 12:08:35 2013 +0200
+++ b/ucx/logging.c	Sat Sep 07 14:08:43 2013 +0200
@@ -61,11 +61,13 @@
     free(logger);
 }
 
+// estimated max. message length (documented)
+#define UCX_LOGGER_MSGMAX 4096
+
 void ucx_logger_logf(UcxLogger *logger, unsigned int level, const char* file,
         const unsigned int line, const char *format, ...) {
     if (level <= logger->level) {
-        const size_t max = 4096; // estimated max. message length (documented)
-        char msg[max];
+        char msg[UCX_LOGGER_MSGMAX];
         char *text;
         size_t k = 0;
         size_t n;
@@ -85,14 +87,18 @@
             n = strlen(file);
             memcpy(msg+k, file, n);
             k += n;
-            k += sprintf(msg+k, ":%d ", line);
+#ifdef _WIN32
+            k += _snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line);
+#else
+            k += snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line);
+#endif /* _WIN32 */
         }
         
         msg[k++] = '-'; msg[k++] = ' ';
         
         va_list args;
         va_start (args, format);
-        k += vsnprintf(msg+k, max-k-1, format, args);
+        k += vsnprintf(msg+k, UCX_LOGGER_MSGMAX-k-1, format, args);
         va_end (args);        
         
         msg[k++] = '\n';

mercurial