From c4dea17af33be0ff8d24fe12536cca59f29b14ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20LeBlanc?= Date: Thu, 7 Nov 2013 13:44:18 -0500 Subject: [PATCH] added _scprintf macro to winpr because snprintf does not count characters on Windows. Modified write_rdp_file_ macros for windows compatibility --- client/common/file.c | 12 ++++++++++-- winpr/include/winpr/string.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client/common/file.c b/client/common/file.c index 40240892d..b7787d096 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -643,7 +643,11 @@ BOOL freerdp_client_write_rdp_file(const rdpFile* file, const char* name, BOOL u #define WRITE_RDP_FILE_VALUE_INTEGER(_format, _field) \ if (~__rdpFile->_field) \ { \ - __count = sprintf_s(__buffer == NULL ? NULL : __buffer + __current, __buffer == NULL ? 0 : __size - __required_size, _format, (int) __rdpFile->_field); \ + if (__buffer) \ + __count = sprintf_s(__buffer + __current, __size - __required_size, _format, (int) __rdpFile->_field); \ + else \ + __count = _scprintf(_format, (int) __rdpFile->_field); \ + \ __required_size += __count; \ __current += __count; \ } @@ -651,7 +655,11 @@ if (~__rdpFile->_field) \ #define WRITE_RDP_FILE_VALUE_STRING(_format, _field) \ if (~((size_t) __rdpFile->_field) && __rdpFile->_field != NULL) \ { \ - __count = sprintf_s(__buffer == NULL ? NULL : __buffer + __current, __buffer == NULL ? 0 : __size - __required_size, _format, __rdpFile->_field); \ + if (buffer) \ + __count = sprintf_s(__buffer + __current, __size - __required_size, _format, __rdpFile->_field); \ + else \ + __count = _scprintf(_format, __rdpFile->_field); \ + \ __required_size += __count; \ __current += __count; \ } diff --git a/winpr/include/winpr/string.h b/winpr/include/winpr/string.h index 8cb2466f0..65cdc5549 100644 --- a/winpr/include/winpr/string.h +++ b/winpr/include/winpr/string.h @@ -153,6 +153,7 @@ WINPR_API int lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2); #endif #define sprintf_s snprintf +#define _scprintf(_fmt, …) snprintf(NULL, 0, _fmt, ## __VAR_ARGS__) /* Unicode Conversion */