changeset 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 433b7c772ff0
children 4bfcad4986ff
files dw.h dwcompat.c dwcompat.h
diffstat 3 files changed, 66 insertions(+), 29 deletions(-) [+]
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__)
--- a/dwcompat.c	Mon Sep 16 17:48:21 2019 +0000
+++ b/dwcompat.c	Mon Sep 16 19:12:39 2019 +0000
@@ -30,29 +30,6 @@
 #include <time.h>
 #include <errno.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)
-static int 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;
-}
-#endif
-
 #if defined(__UNIX__) || defined(__MAC__)
 void msleep(long period)
 {
--- a/dwcompat.h	Mon Sep 16 17:48:21 2019 +0000
+++ b/dwcompat.h	Mon Sep 16 19:12:39 2019 +0000
@@ -102,6 +102,36 @@
 #define API
 #endif
 
+#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
+
+
 #define msleep(a) DosSleep(a)
 
 #ifdef __EMX__
@@ -192,12 +222,6 @@
 #define NO_DOMAIN_SOCKETS
 #endif 
 
-#ifndef PIPEROOT
-#define PIPEROOT "/tmp/"
-#endif
-
-#define PIPENAME "%s" __TARGET__ "%d-%d"
-
 #if defined(_P_NOWAIT) && !defined(P_NOWAIT)
 #define P_NOWAIT _P_NOWAIT
 #endif
@@ -279,6 +303,12 @@
 #define API
 #endif
 
+#ifndef PIPEROOT
+#define PIPEROOT "/tmp/"
+#endif
+
+#define PIPENAME "%s" __TARGET__ "%d-%d"
+
 /* Compatibility layer for IBM C/Winsock
  * Now using macros so we can allow cross
  * compiler support.