From 5e9629763e3e458f97cf839afa8e460f11ad255c Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 24 Apr 2009 14:17:17 +0000 Subject: [PATCH] 2009-04-24 16:24 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapi.h * harbour/source/common/hbprintf.c * harbour/source/common/hbstr.c + added hb_vsnprintf() - vsnprintf() replacement * synced type of parameters in hb_snprintf() used for builds with and without HB__USE_OWN_SNPRINTF --- harbour/ChangeLog | 8 +++++ harbour/include/hbapi.h | 5 +--- harbour/source/common/hbprintf.c | 51 ++++++++++++++++++++++++++++++-- harbour/source/common/hbstr.c | 40 ------------------------- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f05d0bd99a..a263c5bedc 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,14 @@ 2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2009-04-24 16:24 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbapi.h + * harbour/source/common/hbprintf.c + * harbour/source/common/hbstr.c + + added hb_vsnprintf() - vsnprintf() replacement + * synced type of parameters in hb_snprintf() used for builds with and + without HB__USE_OWN_SNPRINTF + 2009-04-24 13:42 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * bin/postinst.bat + Added support for HB_BUILD_IMPLIB for mingw. diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index fd28a3efb2..6b304ad19c 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -871,11 +871,8 @@ extern HB_EXPORT BOOL hb_compStrToNum( const char * szNum, ULONG ulLen, HB_ extern HB_EXPORT BOOL hb_valStrnToNum( const char * szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ); /* converts string to number, sets iDec, iWidth and returns TRUE if results is double, used by VAL() */ extern HB_EXPORT BOOL hb_strToNum( const char * szNum, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ extern HB_EXPORT BOOL hb_strnToNum( const char * szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ -#if defined( HB__USE_OWN_SNPRINTF ) extern HB_EXPORT int hb_snprintf( char * buffer, size_t bufsize, const char * format, ... ) HB_PRINTF_FORMAT( 3, 4 ); /* snprintf() equivalent */ -#else -extern HB_EXPORT ULONG hb_snprintf( char * buffer, ULONG nSize, const char * format, ... ) HB_PRINTF_FORMAT( 3, 4 ); /* snprintf() wrapper */ -#endif +extern HB_EXPORT int hb_vsnprintf( char * buffer, size_t bufsize, const char * format, va_list ap ); /* vsnprintf() equivalent */ extern HB_EXPORT BOOL hb_strMatchFile( const char * pszString, const char * szPattern ); /* compare two strings using platform dependent rules for file matching */ extern HB_EXPORT BOOL hb_strMatchRegExp( const char * szString, const char * szPattern ); /* compare two strings using a regular expression pattern */ diff --git a/harbour/source/common/hbprintf.c b/harbour/source/common/hbprintf.c index df90b764ed..77d0796a57 100644 --- a/harbour/source/common/hbprintf.c +++ b/harbour/source/common/hbprintf.c @@ -836,7 +836,7 @@ static size_t put_str( char *buffer, size_t bufsize, size_t size, return size; } -int hb_snprintf( char * buffer, size_t bufsize, const char * format, ... ) +int hb_vsnprintf( char * buffer, size_t bufsize, const char * format, va_list ap ) { va_list args; size_t size; @@ -858,13 +858,13 @@ int hb_snprintf( char * buffer, size_t bufsize, const char * format, ... ) params.repeat = FALSE; if( params.maxarg > 0 ) { - va_start( args, format ); + va_copy( args, ap ); va_arg_fill( ¶ms, args ); va_end( args ); } format = fmt_start; #endif - va_start( args, format ); + va_copy( args, ap ); size = 0; do @@ -1223,4 +1223,49 @@ int hb_snprintf( char * buffer, size_t bufsize, const char * format, ... ) return ( int ) ( size - 1 ); } +#else /* ! defined( HB__USE_OWN_SNPRINTF ) */ + +#undef _HB_SNPRINTF_ADD_EOS + +/* NOTE: The full size of the buffer is expected as nSize. [vszakats] */ +int hb_vsnprintf( char * buffer, size_t nSize, const char * format, va_list arglist ) +{ + ULONG result; + +#if defined( __DJGPP__ ) && ( __DJGPP__ < 2 || ( __DJGPP__ == 2 && __DJGPP_MINOR__ <= 3 ) ) + /* Use vsprintf() for DJGPP <= 2.03. + This is a temporary hack, should implement a C99 snprintf() ourselves. */ + result = vsprintf( buffer, format, arglist ); + #define _HB_SNPRINTF_ADD_EOS +#elif defined( _MSC_VER ) && _MSC_VER >= 1400 + result = _vsnprintf_s( buffer, nSize, _TRUNCATE, format, arglist ); +#elif ( defined( _MSC_VER ) || defined( __DMC__ ) ) && !defined( __XCC__ ) + result = _vsnprintf( buffer, nSize, format, arglist ); + #define _HB_SNPRINTF_ADD_EOS +#elif defined( __WATCOMC__ ) && __WATCOMC__ < 1200 + result = _vbprintf( buffer, nSize, format, arglist ); +#else + result = vsnprintf( buffer, nSize, format, arglist ); #endif + +#ifdef _HB_SNPRINTF_ADD_EOS + if( buffer && nSize ) + buffer[ nSize - 1 ] = '\0'; +#endif + + return result; +} + +#endif /* HB__USE_OWN_SNPRINTF */ + +int hb_snprintf( char * buffer, size_t bufsize, const char * format, ... ) +{ + va_list ap; + int iResult; + + va_start( ap, format ); + iResult = hb_vsnprintf( buffer, bufsize, format, ap ); + va_end( ap ); + + return iResult; +} diff --git a/harbour/source/common/hbstr.c b/harbour/source/common/hbstr.c index 0a4b483582..d4d4b760f7 100644 --- a/harbour/source/common/hbstr.c +++ b/harbour/source/common/hbstr.c @@ -1089,43 +1089,3 @@ char * hb_compDecodeString( int iMethod, const char * szText, ULONG * pulLen ) } return pBuffer; } - -#if ! defined( HB__USE_OWN_SNPRINTF ) - -#undef _HB_SNPRINTF_ADD_EOS -#undef hb_snprintf -/* NOTE: The full size of the buffer is expected as nSize. [vszakats] */ -ULONG hb_snprintf( char * buffer, ULONG nSize, const char * format, ... ) -{ - va_list arglist; - ULONG result; - - va_start( arglist, format ); - -#if defined( __DJGPP__ ) && ( __DJGPP__ < 2 || ( __DJGPP__ == 2 && __DJGPP_MINOR__ <= 3 ) ) - /* Use vsprintf() for DJGPP <= 2.03. - This is a temporary hack, should implement a C99 snprintf() ourselves. */ - result = vsprintf( buffer, format, arglist ); - #define _HB_SNPRINTF_ADD_EOS -#elif defined( _MSC_VER ) && _MSC_VER >= 1400 - result = _vsnprintf_s( buffer, nSize, _TRUNCATE, format, arglist ); -#elif ( defined( _MSC_VER ) || defined( __DMC__ ) ) && !defined( __XCC__ ) - result = _vsnprintf( buffer, nSize, format, arglist ); - #define _HB_SNPRINTF_ADD_EOS -#elif defined( __WATCOMC__ ) && __WATCOMC__ < 1200 - result = _vbprintf( buffer, nSize, format, arglist ); -#else - result = vsnprintf( buffer, nSize, format, arglist ); -#endif - - va_end( arglist ); - -#ifdef _HB_SNPRINTF_ADD_EOS - if( buffer && nSize ) - buffer[ nSize - 1 ] = '\0'; -#endif - - return result; -} - -#endif