changeset 1990:433b7c772ff0

OS/2: Mostly safe snprintf() for VisualAge.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 16 Sep 2019 17:48:21 +0000
parents 1dd49705bd1a
children d83a86f5fe7f
files dwcompat.c
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dwcompat.c	Mon Sep 16 08:58:58 2019 +0000
+++ b/dwcompat.c	Mon Sep 16 17:48:21 2019 +0000
@@ -30,6 +30,29 @@
 #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)
 {