2009-03-05 19:44 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbapi.h
* harbour/include/hbwince.h
* harbour/source/common/hbgete.c
* harbour/source/common/hbwince.c
+ added BOOL hb_setenv( const char * szName, const char * szValue )
It sets or deletes (szValue==NULL) environment variable.
Please add support for other compilers/OS-es or define
unsupported platforms to eliminate TODO warning.
For sure OS2 version have to be updated.
* harbour/source/rtl/gete.c
+ added .prg function:
HB_SETENV( <cEnvName>, [<cNewVal>] [, <lOsCP>] ) -> <lOK>
which sets or deletes (when <cNewVal> is NIL) process environment
variable <cEnvName>. <lOsCP> controls character translation to
OS encoding. By default is enabled.
TOFIX: <cEnvName> OS character encoding is missing in [HB_]_GETENV()
This commit is contained in:
@@ -8,6 +8,25 @@
|
||||
2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
|
||||
*/
|
||||
|
||||
2009-03-05 19:44 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
|
||||
* harbour/include/hbapi.h
|
||||
* harbour/include/hbwince.h
|
||||
* harbour/source/common/hbgete.c
|
||||
* harbour/source/common/hbwince.c
|
||||
+ added BOOL hb_setenv( const char * szName, const char * szValue )
|
||||
It sets or deletes (szValue==NULL) environment variable.
|
||||
Please add support for other compilers/OS-es or define
|
||||
unsupported platforms to eliminate TODO warning.
|
||||
For sure OS2 version have to be updated.
|
||||
|
||||
* harbour/source/rtl/gete.c
|
||||
+ added .prg function:
|
||||
HB_SETENV( <cEnvName>, [<cNewVal>] [, <lOsCP>] ) -> <lOK>
|
||||
which sets or deletes (when <cNewVal> is NIL) process environment
|
||||
variable <cEnvName>. <lOsCP> controls character translation to
|
||||
OS encoding. By default is enabled.
|
||||
TOFIX: <cEnvName> OS character encoding is missing in [HB_]_GETENV()
|
||||
|
||||
2009-03-05 18:10 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
|
||||
* harbour/source/common/hbprintf.c
|
||||
* do not use modfl() in WinCE POCC builds. If MSVC also does not
|
||||
|
||||
@@ -1044,6 +1044,7 @@ extern HB_EXPORT BYTE * hb_osDecode( BYTE * szFileName, BOOL * pfFree ); /* Conv
|
||||
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 BOOL hb_setenv( const char * szName, const char * szValue ); /* set or delete (szValue==NULL) environment variable */
|
||||
extern char * hb_netname( void );
|
||||
extern char * hb_username( void );
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ extern char *strerror( int errnum );
|
||||
#endif
|
||||
|
||||
DWORD WINAPI GetEnvironmentVariableA( LPCSTR name, LPSTR value, DWORD size );
|
||||
BOOL WINAPI SetEnvironmentVariableA( LPCSTR name, LPCSTR value );
|
||||
LPSTR WINAPI GetEnvironmentStringsA( void );
|
||||
BOOL WINAPI GetProcessTimes( HANDLE hprocess,
|
||||
LPFILETIME lpCreationTime, LPFILETIME lpExitTime,
|
||||
|
||||
@@ -146,3 +146,54 @@ BOOL hb_getenv_buffer( const char * szName, char * szBuffer, int nSize )
|
||||
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
/* set current process environment variable, if szValue is NULL delete
|
||||
* environment variable
|
||||
*/
|
||||
BOOL hb_setenv( const char * szName, const char * szValue )
|
||||
{
|
||||
#if defined(HB_OS_WIN)
|
||||
|
||||
return SetEnvironmentVariableA( szName, szValue ) != 0;
|
||||
|
||||
#elif defined( _BSD_SOURCE ) || _POSIX_C_SOURCE >= 200112L || \
|
||||
_XOPEN_SOURCE >= 600 || defined( __WATCOMC__ ) || defined( __DJGPP__ )
|
||||
|
||||
if( szValue )
|
||||
return setenv( szName, szValue, 1 ) == 0;
|
||||
else
|
||||
{
|
||||
# if defined( __DJGPP__ ) && ( __DJGPP__ < 2 || ( __DJGPP__ == 2 && __DJGPP_MINOR__ < 4 ) )
|
||||
szValue = getenv( szName );
|
||||
if( szValue && *szValue )
|
||||
return setenv( szName, "", 1 ) == 0;
|
||||
else
|
||||
return TRUE;
|
||||
# else
|
||||
return unsetenv( szName ) == 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
#elif defined( _HB_NO_SETENV_ )
|
||||
|
||||
HB_SYMBOL_UNUSED( szName );
|
||||
HB_SYMBOL_UNUSED( szValue );
|
||||
|
||||
return FALSE;
|
||||
|
||||
#else
|
||||
/* please add support for other C compilers
|
||||
* if such functionality does not exists for given platform/C compiler
|
||||
* then please simply added C compiler with necessary OS/version checking
|
||||
* to the above #elif ... to eliminate warning [druzus]
|
||||
*/
|
||||
|
||||
int TODO;
|
||||
|
||||
HB_SYMBOL_UNUSED( szName );
|
||||
HB_SYMBOL_UNUSED( szValue );
|
||||
|
||||
return FALSE;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -228,6 +228,14 @@ DWORD WINAPI GetEnvironmentVariableA( LPCSTR name, LPSTR value, DWORD size )
|
||||
return size;
|
||||
}
|
||||
|
||||
BOOL WINAPI SetEnvironmentVariableA( LPCSTR name, LPCSTR value )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( name );
|
||||
HB_SYMBOL_UNUSED( value );
|
||||
|
||||
/* TODO: */
|
||||
}
|
||||
|
||||
BOOL WINAPI GetProcessTimes( HANDLE hprocess,
|
||||
LPFILETIME lpCreationTime, LPFILETIME lpExitTime,
|
||||
LPFILETIME lpKernelTime, LPFILETIME lpUserTime )
|
||||
|
||||
@@ -112,13 +112,9 @@ HB_FUNC( GETENV )
|
||||
BOOL fFree;
|
||||
char * pbyResult = ( char * ) hb_osDecode( ( BYTE * ) szValue, &fFree );
|
||||
|
||||
hb_retc_buffer( pbyResult );
|
||||
if( fFree )
|
||||
{
|
||||
hb_retc_buffer( pbyResult );
|
||||
hb_xfree( szValue );
|
||||
}
|
||||
else
|
||||
hb_retc_buffer( szValue );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -198,13 +194,9 @@ HB_FUNC( HB_GETENV )
|
||||
BOOL fFree;
|
||||
char * pbyResult = ( char * ) hb_osDecode( ( BYTE * ) szValue, &fFree );
|
||||
|
||||
hb_retc_buffer( pbyResult );
|
||||
if( fFree )
|
||||
{
|
||||
hb_retc_buffer( pbyResult );
|
||||
hb_xfree( szValue );
|
||||
}
|
||||
else
|
||||
hb_retc_buffer( szValue );
|
||||
}
|
||||
else
|
||||
hb_retc_buffer( szValue );
|
||||
@@ -224,3 +216,31 @@ HB_FUNC( HB_GETENV )
|
||||
else
|
||||
hb_retc( NULL );
|
||||
}
|
||||
|
||||
HB_FUNC( HB_SETENV )
|
||||
{
|
||||
char * pszName = hb_parc( 1 );
|
||||
BOOL fResult = FALSE;
|
||||
|
||||
if( pszName )
|
||||
{
|
||||
char * pszValue = hb_parc( 2 );
|
||||
BOOL fFreeName = FALSE, fFreeVal = FALSE;
|
||||
|
||||
if( ( ! ISLOG( 3 ) || hb_parl( 3 ) ) )
|
||||
{
|
||||
pszName = ( char * ) hb_osEncode( ( BYTE * ) pszName, &fFreeName );
|
||||
if( pszValue )
|
||||
pszValue = ( char * ) hb_osEncode( ( BYTE * ) pszValue, &fFreeVal );
|
||||
}
|
||||
|
||||
fResult = hb_setenv( pszName, pszValue );
|
||||
|
||||
if( fFreeName )
|
||||
hb_xfree( pszName );
|
||||
if( fFreeVal )
|
||||
hb_xfree( pszValue );
|
||||
}
|
||||
|
||||
hb_retl( fResult );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user