diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 48972dad12..aed5ffd8e3 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,15 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-18 10:27 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + * include/hbapi.h + * source/common/hbgete.c + + Added hb_getenv_buffer(). Similar to hb_getenv() but + this one needs a buffer+size to be passed, so no memory + allocation is done by the function. It also return + a BOOL to signal success. It doesn't signal if passed + buffer was too small to store the value. + 2008-10-18 08:36 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/debug/dbgtwin.prg * harbour/source/debug/dbgbrwsr.prg diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 3467cf6ad5..d1f0917137 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -1010,6 +1010,7 @@ extern HB_EXPORT BOOL hb_iswince( void ); /* return .T. if OS is Windows CE or extern HB_EXPORT BOOL hb_printerIsReady( char * pszPrinterName ); /* environment variables access */ +extern BOOL hb_getenv_buffer( const char * szName, char * szBuffer, int nSize ); /* WARNING: This returned pointer must be freed if not NULL using hb_xfree( ( void * ) ptr ); */ extern char * hb_getenv( const char * name ); extern char * hb_netname( void ); diff --git a/harbour/source/common/hbgete.c b/harbour/source/common/hbgete.c index f5775b01dd..e9df9d7da3 100644 --- a/harbour/source/common/hbgete.c +++ b/harbour/source/common/hbgete.c @@ -111,3 +111,52 @@ char * hb_getenv( const char * szName ) return pszBuffer; } + + +BOOL hb_getenv_buffer( const char * szName, char * szBuffer, int nSize ) +{ + BOOL bRetVal = FALSE; + + if( szBuffer != NULL && nSize != 0 ) + { + szBuffer[ 0 ] = '\0'; + +#if defined(HB_OS_WIN_32) + + { + bRetVal = GetEnvironmentVariableA( szName, szBuffer, nSize ) != 0; + } + +#elif defined(HB_OS_OS2) + + { + #ifdef __GNUC__ + PSZ EnvValue = ""; + #else + PCSZ EnvValue = ""; + #endif + + if( DosScanEnv( szName, &EnvValue ) == NO_ERROR ) + { + hb_strncpy( szBuffer, EnvValue, nSize - 1 ); + bRetVal = TRUE; + } + } + +#else + + { + char * pszTemp = getenv( szName ); + + if( pszTemp != NULL ) + { + hb_strncpy( szBuffer, pszTemp, nSize - 1 ); + bRetVal = TRUE; + } + } + +#endif + } + + return bRetVal; +}