# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1568661159 0 # Node ID d83a86f5fe7f4f1d5892da31e520a0335c9d07bf # Parent 433b7c772ff0370c5f711a17c2544e84c32d065e 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. diff -r 433b7c772ff0 -r d83a86f5fe7f dw.h --- 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 + +/* 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 +#include +#include +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__) diff -r 433b7c772ff0 -r d83a86f5fe7f dwcompat.c --- 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 #include -/* 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) { diff -r 433b7c772ff0 -r d83a86f5fe7f dwcompat.h --- 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 + +/* 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 +#include +#include +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.