From 1a71aa5b61cfda5ecff1f4352f1aa99ad2f631b3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 15 Oct 2009 13:56:40 +0000 Subject: [PATCH] 2009-10-15 15:55 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/common/hbgete.c * src/rtl/filesys.c * src/rtl/net.c + Changed to use native instead of fixed ANSI version of win API calls. ; Please review me, all these are critical low level functions, so any mistakes can be deadly. ; TODO: There are still some forced ANSI calls in Harbour code: (plus some dynamically called ones) --- source/common/hbver.c:264: if( GetVersionExA( &osVer ) ) source/common/hbver.c:306: if( GetVersionExA( ( OSVERSIONINFOA * ) &osVerEx ) ) source/rtl/fstemp.c:153: if( ! GetTempPathA( ( DWORD ) ( HB_PATH_MAX - 1 ), pszName ) ) source/rtl/fstemp.c:270: if( ! GetTempPathA( ( DWORD ) HB_PATH_MAX, szTempDir ) ) source/rtl/fstemp.c:278: fResult = GetTempFileNameA( szTempDir, pszPrefix ? pszPrefix : "hb", 0, pszBuffer ); contrib/hbwin/win_prn2.c:169: DWORD dwSize = GetProfileStringA( "windows", "device", "", pPrinterName, *pdwBufferSize ); --- * src/rtl/fstemp.c * Minor formatting. --- harbour/ChangeLog | 23 +++++++++++++++++++++++ harbour/src/common/hbgete.c | 23 +++++++++++++++++++---- harbour/src/rtl/filesys.c | 14 ++++++++------ harbour/src/rtl/fstemp.c | 2 +- harbour/src/rtl/net.c | 26 ++++++++++++++++++++------ 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 72d23be8d0..c111df09f5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,28 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-10-15 15:55 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * src/common/hbgete.c + * src/rtl/filesys.c + * src/rtl/net.c + + Changed to use native instead of fixed ANSI version of win API calls. + ; Please review me, all these are critical low level functions, + so any mistakes can be deadly. + + ; TODO: There are still some forced ANSI calls in Harbour code: + (plus some dynamically called ones) + --- + source/common/hbver.c:264: if( GetVersionExA( &osVer ) ) + source/common/hbver.c:306: if( GetVersionExA( ( OSVERSIONINFOA * ) &osVerEx ) ) + source/rtl/fstemp.c:153: if( ! GetTempPathA( ( DWORD ) ( HB_PATH_MAX - 1 ), pszName ) ) + source/rtl/fstemp.c:270: if( ! GetTempPathA( ( DWORD ) HB_PATH_MAX, szTempDir ) ) + source/rtl/fstemp.c:278: fResult = GetTempFileNameA( szTempDir, pszPrefix ? pszPrefix : "hb", 0, pszBuffer ); + contrib/hbwin/win_prn2.c:169: DWORD dwSize = GetProfileStringA( "windows", "device", "", pPrinterName, *pdwBufferSize ); + --- + + * src/rtl/fstemp.c + * Minor formatting. + 2009-10-15 13:49 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * utils/hbmk2/hbmk2.pt_BR.po * utils/hbmk2/hbmk2.hu_HU.po @@ -1683,6 +1705,7 @@ source/rtl/net.c:186: GetUserNameA( pszValue, &ulLen ); contrib/hbwin/win_prn2.c:169: DWORD dwSize = GetProfileStringA( "windows", "device", "", pPrinterName, *pdwBufferSize ); --- + [DONE] ; Review me. diff --git a/harbour/src/common/hbgete.c b/harbour/src/common/hbgete.c index 0dd01093b3..32413f3a52 100644 --- a/harbour/src/common/hbgete.c +++ b/harbour/src/common/hbgete.c @@ -72,13 +72,20 @@ char * hb_getenv( const char * szName ) #if defined( HB_OS_WIN ) { - DWORD size = GetEnvironmentVariableA( szName, NULL, 0 ); + LPTSTR lpName = HB_TCHAR_CONVTO( szName ); + DWORD size = GetEnvironmentVariable( lpName, NULL, 0 ); if( size != 0 ) { - pszBuffer = ( char * ) hb_xgrab( size ); - GetEnvironmentVariableA( szName, pszBuffer, size ); + LPTSTR lpBuffer = ( LPTSTR ) hb_xgrab( size * sizeof( TCHAR ) ); + GetEnvironmentVariable( lpName, lpBuffer, size ); + pszBuffer = HB_TCHAR_CONVFROM( lpBuffer ); +#if defined( UNICODE ) + HB_TCHAR_FREE( lpBuffer ); +#endif } + + HB_TCHAR_FREE( lpName ); } #elif defined( HB_OS_OS2 ) @@ -110,9 +117,17 @@ BOOL hb_getenv_buffer( const char * szName, char * szBuffer, int nSize ) BOOL bRetVal; #if defined( HB_OS_WIN ) + { + LPTSTR lpName = HB_TCHAR_CONVTO( szName ); + LPTSTR lpBuffer = ( LPTSTR ) hb_xgrab( nSize * sizeof( TCHAR ) ); - bRetVal = GetEnvironmentVariableA( szName, szBuffer, nSize ) != 0; + bRetVal = GetEnvironmentVariable( lpName, lpBuffer, nSize ) != 0; + HB_TCHAR_GETFROM( szBuffer, lpBuffer, nSize ); + + HB_TCHAR_FREE( lpBuffer ); + HB_TCHAR_FREE( lpName ); + } #elif defined( HB_OS_OS2 ) { PSZ EnvValue = ( PSZ ) ""; diff --git a/harbour/src/rtl/filesys.c b/harbour/src/rtl/filesys.c index 574b912520..9bfb2e3079 100644 --- a/harbour/src/rtl/filesys.c +++ b/harbour/src/rtl/filesys.c @@ -2729,12 +2729,14 @@ USHORT hb_fsCurDirBuff( USHORT uiDrive, char * pszBuffer, ULONG ulSize ) #endif #if defined( HB_OS_WIN ) - - hb_vmUnlock(); - fResult = GetCurrentDirectoryA( ulSize, pszBuffer ); - hb_fsSetIOError( fResult, 0 ); - hb_vmLock(); - + { + LPTSTR lpBuffer = ( LPTSTR ) hb_xgrab( ulSize * sizeof( TCHAR ) ); + hb_vmUnlock(); + fResult = GetCurrentDirectory( ulSize, lpBuffer ); + hb_fsSetIOError( fResult, 0 ); + hb_vmLock(); + HB_TCHAR_GETFROM( pszBuffer, lpBuffer, ulSize ); + } #elif defined( HB_OS_OS2 ) && defined( __GNUC__ ) hb_vmUnlock(); diff --git a/harbour/src/rtl/fstemp.c b/harbour/src/rtl/fstemp.c index ee4c3cc35a..545853d6f5 100644 --- a/harbour/src/rtl/fstemp.c +++ b/harbour/src/rtl/fstemp.c @@ -173,7 +173,7 @@ static HB_FHANDLE hb_fsCreateTempLow( const char * pszDir, const char * pszPrefi #endif } - if( pszName[0] != '\0' ) + if( pszName[ 0 ] != '\0' ) { int len = strlen( pszName ); if( pszName[ len - 1 ] != HB_OS_PATH_DELIM_CHR ) diff --git a/harbour/src/rtl/net.c b/harbour/src/rtl/net.c index a9be034e80..4a8d95e8a9 100644 --- a/harbour/src/rtl/net.c +++ b/harbour/src/rtl/net.c @@ -151,10 +151,17 @@ char * hb_netname( void ) #elif defined( HB_OS_WIN ) DWORD ulLen = MAX_COMPUTERNAME_LENGTH + 1; - char * pszValue = ( char * ) hb_xgrab( ulLen ); + LPTSTR lpValue = ( LPTSTR ) hb_xgrab( ulLen * sizeof( TCHAR ) ); + char * pszValue; + + lpValue[ 0 ] = L'\0'; + GetComputerName( lpValue, &ulLen ); + + pszValue = HB_TCHAR_CONVFROM( lpValue ); +#if defined( UNICODE ) + HB_TCHAR_FREE( lpValue ); +#endif - pszValue[ 0 ] = '\0'; - GetComputerNameA( pszValue, &ulLen ); return pszValue; #else @@ -180,10 +187,17 @@ char * hb_username( void ) #elif defined( HB_OS_WIN ) DWORD ulLen = 256; - char * pszValue = ( char * ) hb_xgrab( ulLen ); + LPTSTR lpValue = ( LPTSTR ) hb_xgrab( ulLen * sizeof( TCHAR ) ); + char * pszValue; + + lpValue[ 0 ] = L'\0'; + GetUserName( lpValue, &ulLen ); + + pszValue = HB_TCHAR_CONVFROM( lpValue ); +#if defined( UNICODE ) + HB_TCHAR_FREE( lpValue ); +#endif - pszValue[ 0 ] = '\0'; - GetUserNameA( pszValue, &ulLen ); return pszValue; #else