diff mac/dw.m @ 1306:dbd507f42947

Added dw_debug() logging function which will output a message to the debugging console. On Windows this uses OutputDebugMessage(), on Mac it uses NSLog() ... The other platforms currently just dump it to stderr. Maybe more enhancements to come.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 03 Nov 2011 23:34:10 +0000
parents ca02c24e80c9
children c5db6c70905c
line wrap: on
line diff
--- a/mac/dw.m	Thu Nov 03 10:09:11 2011 +0000
+++ b/mac/dw.m	Thu Nov 03 23:34:10 2011 +0000
@@ -3029,6 +3029,24 @@
 }
 
 /*
+ * Displays a debug message on the console...
+ * Parameters:
+ *           format: printf style format string.
+ *           ...: Additional variables for use in the format.
+ */
+void API dw_debug(char *format, ...)
+{
+   va_list args;
+   char outbuf[1025] = {0};
+
+   va_start(args, format);
+   vsnprintf(outbuf, 1024, format, args);
+   va_end(args);
+   
+   NSLog(@"%s", outbuf);
+}
+   
+/*
  * Displays a Message Box with given text and title..
  * Parameters:
  *           title: The title of the message box.
@@ -3043,10 +3061,10 @@
     NSString *button2 = nil;
     NSString *button3 = nil;
     va_list args;
-    char outbuf[1000];
+    char outbuf[1025] = {0};
 
     va_start(args, format);
-    vsprintf(outbuf, format, args);
+    vsnprintf(outbuf, 1024, format, args);
     va_end(args);
 
     if(flags & DW_MB_OKCANCEL)
@@ -5794,13 +5812,13 @@
     }
     else
     {
-        char textbuffer[100];
+        char textbuffer[101] = {0};
 
         if(type & DW_CFA_ULONG)
         {
             ULONG tmp = *((ULONG *)data);
 
-            sprintf(textbuffer, "%lu", tmp);
+            snprintf(textbuffer, 100, "%lu", tmp);
         }
         else if(type & DW_CFA_DATE)
         {
@@ -6866,9 +6884,9 @@
 {
     DWCalendar *calendar = handle;
     NSDate *date;
-    char buffer[100];
-
-    sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day);
+    char buffer[101];
+
+    snprintf(buffer, 100, "%04d-%02d-%02d 00:00:00 +0600", year, month, day);
 
     date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]];
     [calendar setDateValue:date];
@@ -8795,7 +8813,7 @@
 {
    int len;
    char *newname;
-   char errorbuf[1024];
+   char errorbuf[1025];
 
 
    if(!handle)
@@ -9556,11 +9574,11 @@
  */
 HSHM dw_named_memory_new(void **dest, int size, char *name)
 {
-   char namebuf[1024];
+   char namebuf[1025] = {0};
    struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm));
 
    mkdir("/tmp/.dw", S_IWGRP|S_IWOTH);
-   sprintf(namebuf, "/tmp/.dw/%s", name);
+   snprintf(namebuf, 1024, "/tmp/.dw/%s", name);
 
    if((handle->fd = open(namebuf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0)
    {
@@ -9597,11 +9615,11 @@
  */
 HSHM dw_named_memory_get(void **dest, int size, char *name)
 {
-   char namebuf[1024];
+   char namebuf[1025];
    struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm));
 
    mkdir("/tmp/.dw", S_IWGRP|S_IWOTH);
-   sprintf(namebuf, "/tmp/.dw/%s", name);
+   snprintf(namebuf, 1024, "/tmp/.dw/%s", name);
 
    if((handle->fd = open(namebuf, O_RDWR)) < 0)
    {