diff dw.h @ 1991:d83a86f5fe7f

OS/2: Move internal snprintf() into dw.h and dwcompat.h so it can be used anywhere that includes dw.h or dwcompat.h allowing continued use of VAC. Fix an issue where PIPENAME was erroneously defined in the Windows section, breaking any non-windows systems using domain sockets, like OS/2 with VAC.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 16 Sep 2019 19:12:39 +0000
parents 22e3e829be13
children 77e43d71eaa7
line wrap: on
line diff
--- a/dw.h	Mon Sep 16 17:48:21 2019 +0000
+++ b/dw.h	Mon Sep 16 19:12:39 2019 +0000
@@ -259,6 +259,36 @@
 
 extern HAB dwhab;
 extern HMQ dwhmq;
+
+#include <stdio.h>
+
+/* Mostly safe but slow snprintf() for compilers that don't have it... 
+ * like VisualAge.  So we can write safe code and still use VAC to test.
+ */
+#if defined(__IBMC__) && !defined(snprintf)
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+static int _dw_snprintf(char *str, size_t size, const char *format, ...)
+{
+   va_list args;
+   char *outbuf = calloc(1, size + strlen(format) + 1024);
+   int retval = -1;
+
+   if(outbuf)
+   {
+      va_start(args, format);
+      vsprintf(outbuf, format, args);
+      va_end(args);
+      retval = strlen(outbuf);
+      strncpy(str, outbuf, size);
+      free(outbuf);
+   }
+   return retval;
+}
+#define snprintf _dw_snprintf
+#endif
+
 #endif
 
 #if defined(__MAC__)