From 1038fb15fbaeb48575540cceeac07b90bb790966 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 20 Mar 2012 17:40:34 +0000 Subject: [PATCH] 2012-03-20 18:40 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/include/hbwinuni.h + added HB_FSNAMECONV() macro - it's automatically redirected to hb_fsNameConv() or hb_fsNameConvU16() functions depending on UNICODE windows macro * harbour/include/hbapifs.h * harbour/src/rtl/filesys.c + added hb_fsNameConvU16() C function - it makes similar operatin to hb_fsNameConv() but returns UTF16 string. + added hb_fsPipeUnblock() C function - currently it works only in POSIX systems * HB_FSNAMECONV() instead of HB_TCHAR_*() macros * harbour/src/rtl/hbcom.c * HB_FSNAMECONV() instead of HB_TCHAR_*() macros % encapsulate port open and close operations inside hb_vmUnlock()/hb_vmLock() - on some systems this can be slow operations, i.e. close() is delayed until byte in output buffer are not transmitted. * harbour/src/rtl/hbproces.c % prefer read then write in pipe operations ! in POSIX systems set unblocking mode for PIPE handles in hb_fsProcessRun() function - it fixes potential deadlock * harbour/src/common/strwild.c * formatting * harbour/src/rtl/dircmd.prg % use space( n ) instead of repl( chr( 0 ), n ) for allocating dirty buffer * harbour/src/rtl/gttrm/gttrm.c * harbour/src/rtl/gtsln/kbsln.c * ignore broken UTF8 characters in input --- harbour/ChangeLog | 37 ++ harbour/include/hbapifs.h | 1 + harbour/include/hbwinuni.h | 2 + harbour/src/common/strwild.c | 5 +- harbour/src/rtl/dircmd.prg | 2 +- harbour/src/rtl/filesys.c | 694 ++++++++++++++++++++++------------ harbour/src/rtl/gtsln/kbsln.c | 15 +- harbour/src/rtl/gttrm/gttrm.c | 5 +- harbour/src/rtl/hbcom.c | 32 +- harbour/src/rtl/hbproces.c | 37 +- 10 files changed, 566 insertions(+), 264 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index d7578cfd87..ab6f6909c7 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,43 @@ The license applies to all entries newer than 2009-04-28. */ +2012-03-20 18:40 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * harbour/include/hbwinuni.h + + added HB_FSNAMECONV() macro - it's automatically redirected to + hb_fsNameConv() or hb_fsNameConvU16() functions depending on + UNICODE windows macro + + * harbour/include/hbapifs.h + * harbour/src/rtl/filesys.c + + added hb_fsNameConvU16() C function - it makes similar operatin to + hb_fsNameConv() but returns UTF16 string. + + added hb_fsPipeUnblock() C function - currently it works only + in POSIX systems + * HB_FSNAMECONV() instead of HB_TCHAR_*() macros + + * harbour/src/rtl/hbcom.c + * HB_FSNAMECONV() instead of HB_TCHAR_*() macros + % encapsulate port open and close operations inside + hb_vmUnlock()/hb_vmLock() - on some systems this can + be slow operations, i.e. close() is delayed until + byte in output buffer are not transmitted. + + * harbour/src/rtl/hbproces.c + % prefer read then write in pipe operations + ! in POSIX systems set unblocking mode for PIPE handles in + hb_fsProcessRun() function - it fixes potential deadlock + + * harbour/src/common/strwild.c + * formatting + + * harbour/src/rtl/dircmd.prg + % use space( n ) instead of repl( chr( 0 ), n ) for allocating + dirty buffer + + * harbour/src/rtl/gttrm/gttrm.c + * harbour/src/rtl/gtsln/kbsln.c + * ignore broken UTF8 characters in input + 2012-03-19 12:55 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/contrib/hbmzip/mzip.c ! fixed typo in DOS/Windows/OS2 READONLY attribute translation diff --git a/harbour/include/hbapifs.h b/harbour/include/hbapifs.h index 7b1fc34b0a..1c9ff181de 100644 --- a/harbour/include/hbapifs.h +++ b/harbour/include/hbapifs.h @@ -177,6 +177,7 @@ extern HB_EXPORT HB_SIZE hb_fsWriteLarge ( HB_FHANDLE hFileHandle, const voi extern HB_EXPORT HB_SIZE hb_fsWriteAt ( HB_FHANDLE hFileHandle, const void * pBuff, HB_SIZE nCount, HB_FOFFSET nOffset ); /* write to an open file at given offset from a buffer (>64K) */ extern HB_EXPORT HB_FHANDLE hb_fsPOpen ( const char * pFilename, const char * pMode ); extern HB_EXPORT HB_BOOL hb_fsPipeCreate ( HB_FHANDLE hPipe[ 2 ] ); +extern HB_EXPORT HB_BOOL hb_fsPipeUnblock ( HB_FHANDLE hPipeHandle ); extern HB_EXPORT HB_SIZE hb_fsPipeIsData ( HB_FHANDLE hPipeHandle, HB_SIZE nBufferSize, HB_MAXINT nTimeOut ); extern HB_EXPORT HB_SIZE hb_fsPipeRead ( HB_FHANDLE hPipeHandle, void * buffer, HB_SIZE nSize, HB_MAXINT nTimeOut ); extern HB_EXPORT int hb_fsIsPipeOrSock( HB_FHANDLE hPipeHandle ); diff --git a/harbour/include/hbwinuni.h b/harbour/include/hbwinuni.h index d9fcaa9ef2..12bef92933 100644 --- a/harbour/include/hbwinuni.h +++ b/harbour/include/hbwinuni.h @@ -84,6 +84,7 @@ #define HB_STRNCAT( dst, src, len ) hb_wstrncat( dst, src, len ) #define HB_STRCMP( s1, s2 ) hb_wstrcmp( s1, s2 ) #define HB_STRNCMP( s1, s2, len ) hb_wstrncmp( s1, s2, len ) + #define HB_FSNAMECONV( fname, pfree ) ( *pfree = hb_fsNameConvU16( fname ) ) #else #define HB_PARSTR( n, h, len ) hb_parstr( n, hb_setGetOSCP(), h, len ) #define HB_PARSTRDEF( n, h, len ) hb_strnull( hb_parstr( n, hb_setGetOSCP(), h, len ) ) @@ -109,6 +110,7 @@ #define HB_STRNCAT( dst, src, len ) hb_strncat( dst, src, len ) #define HB_STRCMP( s1, s2 ) strcmp( s1, s2 ) #define HB_STRNCMP( s1, s2, len ) strncmp( s1, s2, len ) + #define HB_FSNAMECONV( fname, pfree ) pfreehb_fsNameConvU16( fname, pfree ) #endif #endif /* HB_OS_WIN */ diff --git a/harbour/src/common/strwild.c b/harbour/src/common/strwild.c index 35cb57df34..73c52175c2 100644 --- a/harbour/src/common/strwild.c +++ b/harbour/src/common/strwild.c @@ -76,7 +76,8 @@ HB_BOOL hb_strMatchWild( const char *szString, const char *szPattern ) fAny = HB_TRUE; i++; } - else if( j < nLen && ( szPattern[i] == '?' || szPattern[i] == szString[j] ) ) + else if( j < nLen && + ( szPattern[i] == '?' || szPattern[i] == szString[j] ) ) { if( fAny ) { @@ -210,7 +211,7 @@ HB_BOOL hb_strMatchCaseWildExact( const char *szString, const char *szPattern ) i = j = nAny = 0; nLen = strlen( szString ); nSize = strlen( szPattern ); - while ( i < nSize || ( j < nLen && !fAny ) ) + while( i < nSize || ( j < nLen && !fAny ) ) { if( i < nSize && szPattern[i] == '*' ) { diff --git a/harbour/src/rtl/dircmd.prg b/harbour/src/rtl/dircmd.prg index 3ebaadb6e7..a247bcf2ef 100644 --- a/harbour/src/rtl/dircmd.prg +++ b/harbour/src/rtl/dircmd.prg @@ -98,7 +98,7 @@ STATIC PROCEDURE PutDBF( aDirEntry ) IF ( fhnd := FOpen( aDirEntry[ F_NAME ] ) ) != F_ERROR - buffer := Replicate( Chr( 0 ), 8 ) + buffer := Space( 8 ) IF FRead( fhnd, @buffer, 8 ) == 8 .AND. ; AScan( { 0x03, 0x06, 0x30, 0x31, 0x83, 0x86, 0xE5, 0xE6, 0xF5, 0xF6 }, ; diff --git a/harbour/src/rtl/filesys.c b/harbour/src/rtl/filesys.c index 29432a9fbf..ed11ec6bf1 100644 --- a/harbour/src/rtl/filesys.c +++ b/harbour/src/rtl/filesys.c @@ -188,6 +188,7 @@ #endif #elif defined( HB_OS_WIN ) #include + #include "hbwinuni.h" #if defined( HB_OS_WIN_CE ) #include "hbwince.h" #endif @@ -857,6 +858,25 @@ int hb_fsIsPipeOrSock( HB_FHANDLE hPipeHandle ) #endif } +HB_BOOL hb_fsPipeUnblock( HB_FHANDLE hPipeHandle ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_fsPipeUnblock(%p)", ( void * ) ( HB_PTRDIFF ) hPipeHandle)); + +#if defined( HB_OS_UNIX ) + { + int ret = fcntl( hPipeHandle, F_GETFL, 0 ); + + if( ret != -1 && ( ret & O_NONBLOCK ) == 0 ) + ret = fcntl( hPipeHandle, F_SETFL, ret | O_NONBLOCK ); + + return ret != -1; + } +#else + HB_SYMBOL_UNUSED( hPipeHandle ); + return HB_FALSE; +#endif +} + HB_SIZE hb_fsPipeIsData( HB_FHANDLE hPipeHandle, HB_SIZE nBufferSize, HB_MAXINT nTimeOut ) { @@ -1005,34 +1025,37 @@ HB_SIZE hb_fsPipeRead( HB_FHANDLE hPipeHandle, void * buffer, HB_SIZE nSize, HB_FHANDLE hb_fsOpen( const char * pFilename, HB_USHORT uiFlags ) { HB_FHANDLE hFileHandle; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsOpen(%s, %hu)", pFilename, uiFlags)); - pFilename = hb_fsNameConv( pFilename, &pszFree ); - #if defined( HB_OS_WIN ) { - LPTSTR lpFilename = HB_TCHAR_CONVTO( pFilename ); + LPTSTR lpFileName, lpFree; DWORD dwMode, dwShare, dwCreat, dwAttr; HANDLE hFile; + lpFileName = HB_FSNAMECONV( pFilename, &lpFree ); + convert_open_flags( HB_FALSE, FC_NORMAL, uiFlags, &dwMode, &dwShare, &dwCreat, &dwAttr ); hb_vmUnlock(); - hFile = CreateFile( lpFilename, dwMode, dwShare, NULL, dwCreat, dwAttr, NULL ); + hFile = CreateFile( lpFileName, dwMode, dwShare, NULL, dwCreat, dwAttr, NULL ); hb_fsSetIOError( hFile != ( HANDLE ) INVALID_HANDLE_VALUE, 0 ); hb_vmLock(); - HB_TCHAR_FREE( lpFilename ); + if( lpFree ) + hb_xfree( lpFree ); hFileHandle = ( HB_FHANDLE ) hFile; } #else { + char * pszFree; int flags, share, attr; unsigned mode; + pFilename = hb_fsNameConv( pFilename, &pszFree ); + convert_open_flags( HB_FALSE, FC_NORMAL, uiFlags, &flags, &mode, &share, &attr ); hb_vmUnlock(); @@ -1052,46 +1075,49 @@ HB_FHANDLE hb_fsOpen( const char * pFilename, HB_USHORT uiFlags ) HB_FAILURE_RETRY( hFileHandle, open( pFilename, flags | share, mode ) ); #endif hb_vmLock(); + + if( pszFree ) + hb_xfree( pszFree ); } #endif - if( pszFree ) - hb_xfree( pszFree ); - return hFileHandle; } HB_FHANDLE hb_fsCreate( const char * pFilename, HB_FATTR ulAttr ) { HB_FHANDLE hFileHandle; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsCreate(%s, %u)", pFilename, ulAttr)); - pFilename = hb_fsNameConv( pFilename, &pszFree ); - #if defined( HB_OS_WIN ) { - LPTSTR lpFilename = HB_TCHAR_CONVTO( pFilename ); + LPTSTR lpFileName, lpFree; DWORD dwMode, dwShare, dwCreat, dwAttr; HANDLE hFile; + lpFileName = HB_FSNAMECONV( pFilename, &lpFree ); + convert_open_flags( HB_TRUE, ulAttr, FO_EXCLUSIVE, &dwMode, &dwShare, &dwCreat, &dwAttr ); hb_vmUnlock(); - hFile = CreateFile( lpFilename, dwMode, dwShare, NULL, dwCreat, dwAttr, NULL ); + hFile = CreateFile( lpFileName, dwMode, dwShare, NULL, dwCreat, dwAttr, NULL ); hb_fsSetIOError( hFile != ( HANDLE ) INVALID_HANDLE_VALUE, 0 ); hb_vmLock(); - HB_TCHAR_FREE( lpFilename ); + if( lpFree ) + hb_xfree( lpFree ); hFileHandle = ( HB_FHANDLE ) hFile; } #else { + char * pszFree; int flags, share, attr; unsigned mode; + pFilename = hb_fsNameConv( pFilename, &pszFree ); + convert_open_flags( HB_TRUE, ulAttr, FO_EXCLUSIVE, &flags, &mode, &share, &attr ); hb_vmUnlock(); @@ -1105,12 +1131,12 @@ HB_FHANDLE hb_fsCreate( const char * pFilename, HB_FATTR ulAttr ) HB_FAILURE_RETRY( hFileHandle, open( pFilename, flags | share, mode ) ); #endif hb_vmLock(); + + if( pszFree ) + hb_xfree( pszFree ); } #endif - if( pszFree ) - hb_xfree( pszFree ); - return hFileHandle; } @@ -1123,34 +1149,37 @@ HB_FHANDLE hb_fsCreate( const char * pFilename, HB_FATTR ulAttr ) HB_FHANDLE hb_fsCreateEx( const char * pFilename, HB_FATTR ulAttr, HB_USHORT uiFlags ) { HB_FHANDLE hFileHandle; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsCreateEx(%s, %u, %hu)", pFilename, ulAttr, uiFlags)); - pFilename = hb_fsNameConv( pFilename, &pszFree ); - #if defined( HB_OS_WIN ) { - LPTSTR lpFilename = HB_TCHAR_CONVTO( pFilename ); + LPTSTR lpFileName, lpFree; DWORD dwMode, dwShare, dwCreat, dwAttr; HANDLE hFile; + lpFileName = HB_FSNAMECONV( pFilename, &lpFree ); + convert_open_flags( HB_TRUE, ulAttr, uiFlags, &dwMode, &dwShare, &dwCreat, &dwAttr ); hb_vmUnlock(); - hFile = CreateFile( lpFilename, dwMode, dwShare, NULL, dwCreat, dwAttr, NULL ); + hFile = CreateFile( lpFileName, dwMode, dwShare, NULL, dwCreat, dwAttr, NULL ); hb_fsSetIOError( hFile != ( HANDLE ) INVALID_HANDLE_VALUE, 0 ); hb_vmLock(); - HB_TCHAR_FREE( lpFilename ); + if( lpFree ) + hb_xfree( lpFree ); hFileHandle = ( HB_FHANDLE ) hFile; } #else { + char * pszFree; int flags, share, attr; unsigned mode; + pFilename = hb_fsNameConv( pFilename, &pszFree ); + convert_open_flags( HB_TRUE, ulAttr, uiFlags, &flags, &mode, &share, &attr ); hb_vmUnlock(); @@ -1161,12 +1190,12 @@ HB_FHANDLE hb_fsCreateEx( const char * pFilename, HB_FATTR ulAttr, HB_USHORT uiF HB_FAILURE_RETRY( hFileHandle, open( pFilename, flags | share, mode ) ); #endif hb_vmLock(); + + if( pszFree ) + hb_xfree( pszFree ); } #endif - if( pszFree ) - hb_xfree( pszFree ); - return hFileHandle; } @@ -1364,22 +1393,21 @@ HB_BOOL hb_fsGetFileTime( const char * pszFileName, long * plJulian, long * plMi HB_BOOL hb_fsGetAttr( const char * pszFileName, HB_FATTR * pulAttr ) { HB_BOOL fResult; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsGetAttr(%s, %p)", pszFileName, pulAttr)); - *pulAttr = 0; - fResult = HB_FALSE; - pszFileName = hb_fsNameConv( pszFileName, &pszFree ); - hb_vmUnlock(); + *pulAttr = 0; + fResult = HB_FALSE; #if defined( HB_OS_WIN ) { - LPTSTR lpFilename = HB_TCHAR_CONVTO( pszFileName ); + LPTSTR lpFileName, lpFree; DWORD dwAttr; - dwAttr = GetFileAttributes( lpFilename ); + lpFileName = HB_FSNAMECONV( pszFileName, &lpFree ); + + dwAttr = GetFileAttributes( lpFileName ); if( dwAttr != INVALID_FILE_ATTRIBUTES ) { @@ -1388,61 +1416,68 @@ HB_BOOL hb_fsGetAttr( const char * pszFileName, HB_FATTR * pulAttr ) } hb_fsSetIOError( fResult, 0 ); - HB_TCHAR_FREE( lpFilename ); - } -#elif defined( HB_OS_DOS ) - { -#if defined( __DJGPP__ ) || defined( __BORLANDC__ ) - int attr = _chmod( pszFileName, 0, 0 ); - if( attr != -1 ) -#else - unsigned int attr = 0; - if( _dos_getfileattr( pszFileName, &attr ) == 0 ) -#endif - { - *pulAttr = hb_fsAttrFromRaw( attr ); - fResult = HB_TRUE; - } - hb_fsSetIOError( fResult, 0 ); - } -#elif defined( HB_OS_OS2 ) - { - FILESTATUS3 fs3; - APIRET ulrc; - - ulrc = DosQueryPathInfo( ( PCSZ ) pszFileName, FIL_STANDARD, &fs3, sizeof( fs3 ) ); - if( ulrc == NO_ERROR ) - { - *pulAttr = hb_fsAttrFromRaw( fs3.attrFile ); - fResult = HB_TRUE; - } - hb_fsSetIOError( fResult, 0 ); - } -#elif defined( HB_OS_UNIX ) - { - struct stat sStat; - - if( stat( pszFileName, &sStat ) == 0 ) - { - *pulAttr = hb_fsAttrFromRaw( sStat.st_mode ); - fResult = HB_TRUE; - } - hb_fsSetIOError( fResult, 0 ); + if( lpFree ) + hb_xfree( lpFree ); } #else { - int iTODO; /* TODO: for given platform */ + char * pszFree; + pszFileName = hb_fsNameConv( pszFileName, &pszFree ); - HB_SYMBOL_UNUSED( pszFileName ); - HB_SYMBOL_UNUSED( pulAttr ); +# if defined( HB_OS_DOS ) + { +# if defined( __DJGPP__ ) || defined( __BORLANDC__ ) + int attr = _chmod( pszFileName, 0, 0 ); + if( attr != -1 ) +# else + unsigned int attr = 0; + if( _dos_getfileattr( pszFileName, &attr ) == 0 ) +# endif + { + *pulAttr = hb_fsAttrFromRaw( attr ); + fResult = HB_TRUE; + } + hb_fsSetIOError( fResult, 0 ); + } +# elif defined( HB_OS_OS2 ) + { + FILESTATUS3 fs3; + APIRET ulrc; + + ulrc = DosQueryPathInfo( ( PCSZ ) pszFileName, FIL_STANDARD, &fs3, sizeof( fs3 ) ); + if( ulrc == NO_ERROR ) + { + *pulAttr = hb_fsAttrFromRaw( fs3.attrFile ); + fResult = HB_TRUE; + } + hb_fsSetIOError( fResult, 0 ); + } +# elif defined( HB_OS_UNIX ) + { + struct stat sStat; + + if( stat( pszFileName, &sStat ) == 0 ) + { + *pulAttr = hb_fsAttrFromRaw( sStat.st_mode ); + fResult = HB_TRUE; + } + hb_fsSetIOError( fResult, 0 ); + } +# else + { + int iTODO; /* TODO: for given platform */ + + HB_SYMBOL_UNUSED( pszFileName ); + HB_SYMBOL_UNUSED( pulAttr ); + } +# endif + if( pszFree ) + hb_xfree( pszFree ); } #endif hb_vmLock(); - if( pszFree ) - hb_xfree( pszFree ); - return fResult; } @@ -1553,11 +1588,11 @@ HB_BOOL hb_fsSetFileTime( const char * pszFileName, long lJulian, long lMillisec if( lJulian <= 0 && lMillisec ) { -#if defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) +# if defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) fResult = utimes( pszFileName, NULL ) == 0; -#else +# else fResult = utime( pszFileName, NULL ) == 0; -#endif +# endif } else { @@ -1596,20 +1631,20 @@ HB_BOOL hb_fsSetFileTime( const char * pszFileName, long lJulian, long lMillisec # else new_value = *gmtime( &tim ); # endif -#if defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) +# if defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) { struct timeval times[ 2 ]; times[ 0 ].tv_sec = times[ 1 ].tv_sec = mktime( &new_value ); times[ 0 ].tv_usec = times[ 1 ].tv_usec = iMSec * 1000; fResult = utimes( pszFileName, times ) == 0; } -#else +# else { struct utimbuf buf; buf.actime = buf.modtime = mktime( &new_value ); fResult = utime( pszFileName, &buf ) == 0; } -#endif +# endif } hb_fsSetIOError( fResult, 0 ); if( pszFree ) @@ -1632,19 +1667,18 @@ HB_BOOL hb_fsSetFileTime( const char * pszFileName, long lJulian, long lMillisec HB_BOOL hb_fsSetAttr( const char * pszFileName, HB_FATTR ulAttr ) { HB_BOOL fResult; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsSetAttr(%s, %u)", pszFileName, ulAttr)); - pszFileName = hb_fsNameConv( pszFileName, &pszFree ); - hb_vmUnlock(); #if defined( HB_OS_WIN ) { - LPTSTR lpFilename = HB_TCHAR_CONVTO( pszFileName ); + LPTSTR lpFileName, lpFree; DWORD dwFlags = FILE_ATTRIBUTE_ARCHIVE; + lpFileName = HB_FSNAMECONV( pszFileName, &lpFree ); + if( ulAttr & HB_FA_READONLY ) dwFlags |= FILE_ATTRIBUTE_READONLY; if( ulAttr & HB_FA_HIDDEN ) @@ -1653,82 +1687,90 @@ HB_BOOL hb_fsSetAttr( const char * pszFileName, HB_FATTR ulAttr ) dwFlags |= FILE_ATTRIBUTE_SYSTEM; if( ulAttr & HB_FA_NORMAL ) dwFlags |= FILE_ATTRIBUTE_NORMAL; - fResult = SetFileAttributes( lpFilename, dwFlags ) != 0; + fResult = SetFileAttributes( lpFileName, dwFlags ) != 0; hb_fsSetIOError( fResult, 0 ); - HB_TCHAR_FREE( lpFilename ); - } -#elif defined( HB_OS_OS2 ) - { - FILESTATUS3 fs3; - APIRET ulrc; - ULONG ulOsAttr = FILE_NORMAL; - - if( ulAttr & HB_FA_READONLY ) - ulOsAttr |= FILE_READONLY; - if( ulAttr & HB_FA_HIDDEN ) - ulOsAttr |= FILE_HIDDEN; - if( ulAttr & HB_FA_SYSTEM ) - ulOsAttr |= FILE_SYSTEM; - if( ulAttr & HB_FA_ARCHIVE ) - ulOsAttr |= FILE_ARCHIVED; - - ulrc = DosQueryPathInfo( ( PCSZ ) pszFileName, FIL_STANDARD, &fs3, sizeof( fs3 ) ); - if( ulrc == NO_ERROR ) - { - fs3.attrFile = ulOsAttr; - ulrc = DosSetPathInfo( ( PCSZ ) pszFileName, FIL_STANDARD, - &fs3, sizeof( fs3 ), DSPI_WRTTHRU ); - } - fResult = ulrc == NO_ERROR; - hb_fsSetIOError( fResult, 0 ); - } -#elif defined( HB_OS_DOS ) - - ulAttr &= ~( HB_FA_ARCHIVE | HB_FA_HIDDEN | HB_FA_READONLY | HB_FA_SYSTEM ); -# if defined( __DJGPP__ ) || defined( __BORLANDC__ ) - fResult = _chmod( pszFileName, 1, ulAttr ) != -1; -# else - fResult = _dos_setfileattr( pszFileName, ulAttr ) != -1; -# endif - hb_fsSetIOError( fResult, 0 ); - -#elif defined( HB_OS_UNIX ) - { - int iAttr = HB_FA_POSIX_ATTR( ulAttr ), iResult; - if( iAttr == 0 ) - { - iAttr = ( ulAttr & HB_FA_HIDDEN ) ? S_IRUSR : ( S_IRUSR | S_IRGRP | S_IROTH ); - if( !( ulAttr & HB_FA_READONLY ) ) - { - if( iAttr & S_IRUSR ) iAttr |= S_IWUSR; - if( iAttr & S_IRGRP ) iAttr |= S_IWGRP; - if( iAttr & S_IROTH ) iAttr |= S_IWOTH; - } - if( ulAttr & HB_FA_SYSTEM ) - { - if( iAttr & S_IRUSR ) iAttr |= S_IXUSR; - if( iAttr & S_IRGRP ) iAttr |= S_IXGRP; - if( iAttr & S_IROTH ) iAttr |= S_IXOTH; - } - } - HB_FAILURE_RETRY( iResult, chmod( pszFileName, iAttr ) ); - fResult = iResult != -1; + if( lpFree ) + hb_xfree( lpFree ); } #else { - int iTODO; /* To force warning */ + char * pszFree; - fResult = HB_FALSE; - hb_fsSetError( ( HB_ERRCODE ) FS_ERROR ); + pszFileName = hb_fsNameConv( pszFileName, &pszFree ); + +# if defined( HB_OS_OS2 ) + { + FILESTATUS3 fs3; + APIRET ulrc; + ULONG ulOsAttr = FILE_NORMAL; + + if( ulAttr & HB_FA_READONLY ) + ulOsAttr |= FILE_READONLY; + if( ulAttr & HB_FA_HIDDEN ) + ulOsAttr |= FILE_HIDDEN; + if( ulAttr & HB_FA_SYSTEM ) + ulOsAttr |= FILE_SYSTEM; + if( ulAttr & HB_FA_ARCHIVE ) + ulOsAttr |= FILE_ARCHIVED; + + ulrc = DosQueryPathInfo( ( PCSZ ) pszFileName, FIL_STANDARD, &fs3, sizeof( fs3 ) ); + if( ulrc == NO_ERROR ) + { + fs3.attrFile = ulOsAttr; + ulrc = DosSetPathInfo( ( PCSZ ) pszFileName, FIL_STANDARD, + &fs3, sizeof( fs3 ), DSPI_WRTTHRU ); + } + fResult = ulrc == NO_ERROR; + hb_fsSetIOError( fResult, 0 ); + } +# elif defined( HB_OS_DOS ) + + ulAttr &= ~( HB_FA_ARCHIVE | HB_FA_HIDDEN | HB_FA_READONLY | HB_FA_SYSTEM ); +# if defined( __DJGPP__ ) || defined( __BORLANDC__ ) + fResult = _chmod( pszFileName, 1, ulAttr ) != -1; +# else + fResult = _dos_setfileattr( pszFileName, ulAttr ) != -1; +# endif + hb_fsSetIOError( fResult, 0 ); + +# elif defined( HB_OS_UNIX ) + { + int iAttr = HB_FA_POSIX_ATTR( ulAttr ), iResult; + if( iAttr == 0 ) + { + iAttr = ( ulAttr & HB_FA_HIDDEN ) ? S_IRUSR : ( S_IRUSR | S_IRGRP | S_IROTH ); + if( !( ulAttr & HB_FA_READONLY ) ) + { + if( iAttr & S_IRUSR ) iAttr |= S_IWUSR; + if( iAttr & S_IRGRP ) iAttr |= S_IWGRP; + if( iAttr & S_IROTH ) iAttr |= S_IWOTH; + } + if( ulAttr & HB_FA_SYSTEM ) + { + if( iAttr & S_IRUSR ) iAttr |= S_IXUSR; + if( iAttr & S_IRGRP ) iAttr |= S_IXGRP; + if( iAttr & S_IROTH ) iAttr |= S_IXOTH; + } + } + HB_FAILURE_RETRY( iResult, chmod( pszFileName, iAttr ) ); + fResult = iResult != -1; + } +# else + { + int iTODO; /* To force warning */ + + fResult = HB_FALSE; + hb_fsSetError( ( HB_ERRCODE ) FS_ERROR ); + } +# endif + if( pszFree ) + hb_xfree( pszFree ); } #endif hb_vmLock(); - if( pszFree ) - hb_xfree( pszFree ); - return fResult; } @@ -2913,187 +2955,229 @@ HB_FOFFSET hb_fsTell( HB_FHANDLE hFileHandle ) HB_BOOL hb_fsDelete( const char * pFilename ) { HB_BOOL fResult; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsDelete(%s)", pFilename)); - pFilename = hb_fsNameConv( pFilename, &pszFree ); - - hb_vmUnlock(); - #if defined( HB_OS_WIN ) { - LPTSTR lpFilename = HB_TCHAR_CONVTO( pFilename ); + LPTSTR lpFileName, lpFree; - fResult = DeleteFile( lpFilename ) != 0; + lpFileName = HB_FSNAMECONV( pFilename, &lpFree ); + + hb_vmUnlock(); + + fResult = DeleteFile( lpFileName ) != 0; hb_fsSetIOError( fResult, 0 ); - HB_TCHAR_FREE( lpFilename ); + hb_vmLock(); + + if( lpFree ) + hb_xfree( lpFree ); } #else + { + char * pszFree; - fResult = ( remove( pFilename ) == 0 ); - hb_fsSetIOError( fResult, 0 ); + pFilename = hb_fsNameConv( pFilename, &pszFree ); + hb_vmUnlock(); + + fResult = ( remove( pFilename ) == 0 ); + hb_fsSetIOError( fResult, 0 ); + + hb_vmLock(); + + if( pszFree ) + hb_xfree( pszFree ); + } #endif - hb_vmLock(); - - if( pszFree ) - hb_xfree( pszFree ); - return fResult; } HB_BOOL hb_fsRename( const char * pOldName, const char * pNewName ) { HB_BOOL fResult; - char * pszFreeOld, * pszFreeNew; HB_TRACE(HB_TR_DEBUG, ("hb_fsRename(%s, %s)", pOldName, pNewName)); - pOldName = hb_fsNameConv( pOldName, &pszFreeOld ); - pNewName = hb_fsNameConv( pNewName, &pszFreeNew ); - - hb_vmUnlock(); - #if defined( HB_OS_WIN ) - { - LPTSTR lpOldName = HB_TCHAR_CONVTO( pOldName ); - LPTSTR lpNewName = HB_TCHAR_CONVTO( pNewName ); + LPTSTR lpOldName, lpNewName, lpOldFree, lpNewFree; + + lpOldName = HB_FSNAMECONV( pOldName, &lpOldFree ); + lpNewName = HB_FSNAMECONV( pNewName, &lpNewFree ); + + hb_vmUnlock(); fResult = MoveFile( lpOldName, lpNewName ) != 0; hb_fsSetIOError( fResult, 0 ); - HB_TCHAR_FREE( lpOldName ); - HB_TCHAR_FREE( lpNewName ); + hb_vmLock(); + + if( lpOldFree ) + hb_xfree( lpOldFree ); + if( lpNewFree ) + hb_xfree( lpNewFree ); } - #else + { + char * pszFreeOld, * pszFreeNew; - fResult = ( rename( pOldName, pNewName ) == 0 ); - hb_fsSetIOError( fResult, 0 ); + pOldName = hb_fsNameConv( pOldName, &pszFreeOld ); + pNewName = hb_fsNameConv( pNewName, &pszFreeNew ); + hb_vmUnlock(); + + fResult = ( rename( pOldName, pNewName ) == 0 ); + hb_fsSetIOError( fResult, 0 ); + + hb_vmLock(); + + if( pszFreeOld ) + hb_xfree( pszFreeOld ); + if( pszFreeNew ) + hb_xfree( pszFreeNew ); + } #endif - hb_vmLock(); - - if( pszFreeOld ) - hb_xfree( pszFreeOld ); - if( pszFreeNew ) - hb_xfree( pszFreeNew ); - return fResult; } HB_BOOL hb_fsMkDir( const char * pDirname ) { HB_BOOL fResult; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsMkDir(%s)", pDirname)); - pDirname = hb_fsNameConv( pDirname, &pszFree ); - - hb_vmUnlock(); - #if defined( HB_OS_WIN ) { - LPTSTR lpDirname = HB_TCHAR_CONVTO( pDirname ); + LPTSTR lpDirname, lpFree; + + lpDirname = HB_FSNAMECONV( pDirname, &lpFree ); + + hb_vmUnlock(); fResult = CreateDirectory( lpDirname, NULL ) != 0; hb_fsSetIOError( fResult, 0 ); - HB_TCHAR_FREE( lpDirname ); + hb_vmLock(); + + if( lpFree ) + hb_xfree( lpFree ); } #else + { + char * pszFree; + + pDirname = hb_fsNameConv( pDirname, &pszFree ); + + hb_vmUnlock(); # if ! defined( HB_OS_UNIX ) && \ ( defined( __WATCOMC__ ) || defined( __BORLANDC__ ) || \ defined( __IBMCPP__ ) || defined( __MINGW32__ ) ) - fResult = ( mkdir( pDirname ) == 0 ); + fResult = ( mkdir( pDirname ) == 0 ); # else - fResult = ( mkdir( pDirname, S_IRWXU | S_IRWXG | S_IRWXO ) == 0 ); + fResult = ( mkdir( pDirname, S_IRWXU | S_IRWXG | S_IRWXO ) == 0 ); # endif - hb_fsSetIOError( fResult, 0 ); + hb_fsSetIOError( fResult, 0 ); + hb_vmLock(); + + if( pszFree ) + hb_xfree( pszFree ); + } #endif - hb_vmLock(); - - if( pszFree ) - hb_xfree( pszFree ); - return fResult; } HB_BOOL hb_fsChDir( const char * pDirname ) { HB_BOOL fResult; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsChDir(%s)", pDirname)); - pDirname = hb_fsNameConv( pDirname, &pszFree ); - - hb_vmUnlock(); - #if defined( HB_OS_WIN ) { - LPTSTR lpDirname = HB_TCHAR_CONVTO( pDirname ); + LPTSTR lpDirname, lpFree; UINT uiErrMode; + lpDirname = HB_FSNAMECONV( pDirname, &lpFree ); + + hb_vmUnlock(); + uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS ); fResult = SetCurrentDirectory( lpDirname ) != FALSE; SetErrorMode( uiErrMode ); hb_fsSetIOError( fResult, 0 ); - HB_TCHAR_FREE( lpDirname ); + hb_vmLock(); + + if( lpFree ) + hb_xfree( lpFree ); } #else - fResult = ( chdir( pDirname ) == 0 ); - hb_fsSetIOError( fResult, 0 ); + { + char * pszFree; + + pDirname = hb_fsNameConv( pDirname, &pszFree ); + + + fResult = ( chdir( pDirname ) == 0 ); + hb_fsSetIOError( fResult, 0 ); + + hb_vmLock(); + + if( pszFree ) + hb_xfree( pszFree ); + } #endif - hb_vmLock(); - - if( pszFree ) - hb_xfree( pszFree ); - return fResult; } HB_BOOL hb_fsRmDir( const char * pDirname ) { HB_BOOL fResult; - char * pszFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsRmDir(%s)", pDirname)); - pDirname = hb_fsNameConv( pDirname, &pszFree ); - - hb_vmUnlock(); - #if defined( HB_OS_WIN ) { - LPTSTR lpDirname = HB_TCHAR_CONVTO( pDirname ); + LPTSTR lpDirname, lpFree; + + lpDirname = HB_FSNAMECONV( pDirname, &lpFree ); + + hb_vmUnlock(); fResult = RemoveDirectory( lpDirname ) != 0; hb_fsSetIOError( fResult, 0 ); - HB_TCHAR_FREE( lpDirname ); + hb_vmLock(); + + if( lpFree ) + hb_xfree( lpFree ); } #else - fResult = ( rmdir( pDirname ) == 0 ); - hb_fsSetIOError( fResult, 0 ); + { + char * pszFree; + + pDirname = hb_fsNameConv( pDirname, &pszFree ); + + hb_vmUnlock(); + + fResult = ( rmdir( pDirname ) == 0 ); + hb_fsSetIOError( fResult, 0 ); + + hb_vmLock(); + + if( pszFree ) + hb_xfree( pszFree ); + } #endif - hb_vmLock(); - - if( pszFree ) - hb_xfree( pszFree ); - return fResult; } @@ -3659,6 +3743,16 @@ const char * hb_fsNameConv( const char * szFileName, char ** pszFree ) cDirSep = ( char ) hb_setGetDirSeparator(); iFileCase = hb_setGetFileCase(); iDirCase = hb_setGetDirCase(); + if( fTrim ) + { + if( strchr( szFileName, ' ' ) == NULL ) + fTrim = HB_FALSE; + } + if( cDirSep != HB_OS_PATH_DELIM_CHR ) + { + if( strchr( szFileName, ( HB_UCHAR ) cDirSep ) == NULL ) + cDirSep = HB_OS_PATH_DELIM_CHR; + } if( fTrim || fEncodeCP || cDirSep != HB_OS_PATH_DELIM_CHR || @@ -3758,6 +3852,138 @@ const char * hb_fsNameConv( const char * szFileName, char ** pszFree ) return szFileName; } +#if defined( HB_OS_WIN ) +HB_WCHAR * hb_fsNameConvU16( const char * szFileName ) +{ + char * pszBuffer = NULL; + HB_WCHAR * lpwFileName; + HB_SIZE nLen; + PHB_CODEPAGE cdp; + int iFileCase, iDirCase; + char cDirSep; + HB_BOOL fTrim; + +/* + Convert file and dir case. The allowed SET options are: + LOWER - Convert all caracters of file to lower + UPPER - Convert all caracters of file to upper + MIXED - Leave as is + + The allowed environment options are: + FILECASE - define the case of file + DIRCASE - define the case of path + DIRSEPARATOR - define separator of path (Ex. "/") + TRIMFILENAME - strip trailing and leading spaces (also from extension) +*/ + + if( !hb_stackId() ) + return hb_mbtowc( szFileName ); + + cdp = hb_vmCDP(); + fTrim = hb_setGetTrimFileName(); + cDirSep = ( char ) hb_setGetDirSeparator(); + iFileCase = hb_setGetFileCase(); + iDirCase = hb_setGetDirCase(); + if( fTrim ) + { + if( strchr( szFileName, ' ' ) == NULL ) + fTrim = HB_FALSE; + } + if( cDirSep != HB_OS_PATH_DELIM_CHR ) + { + if( strchr( szFileName, ( HB_UCHAR ) cDirSep ) == NULL ) + cDirSep = HB_OS_PATH_DELIM_CHR; + } + + if( fTrim || + cDirSep != HB_OS_PATH_DELIM_CHR || + iFileCase != HB_SET_CASE_MIXED || + iDirCase != HB_SET_CASE_MIXED ) + { + char * pszPath = NULL, * pszName = NULL, * pszExt = NULL; + PHB_FNAME pFileName; + + szFileName = pszBuffer = hb_strncpy( ( char * ) hb_xgrab( HB_PATH_MAX ), + szFileName, HB_PATH_MAX - 1 ); + + if( cDirSep != HB_OS_PATH_DELIM_CHR ) + { + char * p = pszBuffer; + while( *p ) + { + if( *p == cDirSep ) + *p = HB_OS_PATH_DELIM_CHR; + p++; + } + } + + pFileName = hb_fsFNameSplit( pszBuffer ); + + /* strip trailing and leading spaces */ + if( fTrim ) + { + if( pFileName->szName ) + { + nLen = strlen( pFileName->szName ); + nLen = hb_strRTrimLen( pFileName->szName, nLen, HB_FALSE ); + pFileName->szName = hb_strLTrim( pFileName->szName, &nLen ); + ( ( char * ) pFileName->szName )[ nLen ] = '\0'; + } + if( pFileName->szExtension ) + { + nLen = strlen( pFileName->szExtension ); + nLen = hb_strRTrimLen( pFileName->szExtension, nLen, HB_FALSE ); + pFileName->szExtension = hb_strLTrim( pFileName->szExtension, &nLen ); + ( ( char * ) pFileName->szExtension )[ nLen ] = '\0'; + } + } + + /* FILECASE */ + if( iFileCase == HB_SET_CASE_LOWER ) + { + if( pFileName->szName ) + pFileName->szName = pszName = hb_cdpnDupLower( hb_vmCDP(), pFileName->szName, NULL ); + if( pFileName->szExtension ) + pFileName->szExtension = pszExt = hb_cdpnDupLower( hb_vmCDP(), pFileName->szExtension, NULL ); + } + else if( iFileCase == HB_SET_CASE_UPPER ) + { + if( pFileName->szName ) + pFileName->szName = pszName = hb_cdpnDupUpper( hb_vmCDP(), pFileName->szName, NULL ); + if( pFileName->szExtension ) + pFileName->szExtension = pszExt = hb_cdpnDupUpper( hb_vmCDP(), pFileName->szExtension, NULL ); + } + + /* DIRCASE */ + if( pFileName->szPath ) + { + if( iDirCase == HB_SET_CASE_LOWER ) + pFileName->szPath = pszPath = hb_cdpnDupLower( hb_vmCDP(), pFileName->szPath, NULL ); + else if( iDirCase == HB_SET_CASE_UPPER ) + pFileName->szPath = pszPath = hb_cdpnDupUpper( hb_vmCDP(), pFileName->szPath, NULL ); + } + + hb_fsFNameMerge( pszBuffer, pFileName ); + hb_xfree( pFileName ); + if( pszPath ) + hb_xfree( pszPath ); + if( pszName ) + hb_xfree( pszName ); + if( pszExt ) + hb_xfree( pszExt ); + } + + nLen = hb_cdpStrAsU16Len( hb_vmCDP(), szFileName, strlen( szFileName ), 0 ); + lpwFileName = ( HB_WCHAR * ) hb_xgrab( ( nLen + 1 ) * sizeof( HB_WCHAR ) ); + hb_cdpStrToU16( cdp, HB_CDP_ENDIAN_NATIVE, szFileName, strlen( szFileName ), + lpwFileName, nLen + 1 ); + if( pszBuffer ) + hb_xfree( pszBuffer ); + + return lpwFileName; +} +#endif /* HB_OS_WIN */ + /* NOTE: pszBuffer must be HB_PATH_MAX long. */ void hb_fsBaseDirBuff( char * pszBuffer ) { diff --git a/harbour/src/rtl/gtsln/kbsln.c b/harbour/src/rtl/gtsln/kbsln.c index a92ecd1b94..10a35ac860 100644 --- a/harbour/src/rtl/gtsln/kbsln.c +++ b/harbour/src/rtl/gtsln/kbsln.c @@ -429,7 +429,7 @@ int hb_gt_sln_ReadKey( PHB_GT pGT, int iEventMask ) int n = 0; HB_USHORT uc = 0; - if( hb_cdpGetFromUTF8( hb_sln_cdpIN, ( HB_BYTE ) ch, &n, &uc ) ) + if( hb_cdpGetFromUTF8( hb_sln_cdpIN, ( HB_UCHAR ) ch, &n, &uc ) ) { unsigned int buf[ 10 ], i = 0; @@ -439,16 +439,13 @@ int hb_gt_sln_ReadKey( PHB_GT pGT, int iEventMask ) - HB_MAX( hb_sln_escDelay, 0 ) ) == 0 ) break; buf[ i++ ] = SLang_getkey(); - if( !hb_cdpGetFromUTF8( hb_sln_cdpIN, ( HB_BYTE ) buf[ i - 1 ], &n, &uc ) ) - break; + if( !hb_cdpGetFromUTF8( hb_sln_cdpIN, ( HB_UCHAR ) buf[ i - 1 ], &n, &uc ) ) + n = -1; } - if( n > 0 ) - { - while( i > 0 ) - SLang_ungetkey( buf[ --i ] ); - } - else + if( n == 0 ) ch = uc; + else while( i > 0 ) + SLang_ungetkey( buf[ --i ] ); } } #endif diff --git a/harbour/src/rtl/gttrm/gttrm.c b/harbour/src/rtl/gttrm/gttrm.c index 3283d9ba8a..14dce93a73 100644 --- a/harbour/src/rtl/gttrm/gttrm.c +++ b/harbour/src/rtl/gttrm/gttrm.c @@ -1477,9 +1477,10 @@ again: while( n > 0 ) { ch = test_bufch( pTerm, i++, pTerm->esc_delay ); - if( ch < 0 || ch > 255 || - !hb_cdpGetFromUTF8( pTerm->cdpIn, ch, &n, &uc ) ) + if( ch < 0 || ch > 255 ) break; + if( !hb_cdpGetFromUTF8( pTerm->cdpIn, ch, &n, &uc ) ) + n = -1; } if( n == 0 ) { diff --git a/harbour/src/rtl/hbcom.c b/harbour/src/rtl/hbcom.c index 0a4eee05f8..435558f8a2 100644 --- a/harbour/src/rtl/hbcom.c +++ b/harbour/src/rtl/hbcom.c @@ -102,6 +102,7 @@ # include "../../src/3rd/hbpmcom/com.h" #elif defined( HB_OS_WIN ) # include +# include "hbwinuni.h" #elif defined( HB_OS_OS2 ) # define INCL_BASE # define INCL_DOS @@ -1235,6 +1236,7 @@ int hb_comClose( int iPort ) if( pCom ) { + hb_vmUnlock(); #if defined( TIOCNXCL ) ioctl( pCom->fd, TIOCNXCL ); #endif @@ -1250,6 +1252,7 @@ int hb_comClose( int iPort ) pCom->fd = ( HB_FHANDLE ) FS_ERROR; pCom->status &= ~HB_COM_OPEN; } + hb_vmLock(); } return iResult; @@ -1271,6 +1274,8 @@ int hb_comOpen( int iPort ) char buffer[ HB_COM_DEV_NAME_MAX ]; const char * name = hb_comGetName( pCom, buffer, sizeof( buffer ) ); + hb_vmUnlock(); + pCom->fd = open( name, O_RDWR | O_NOCTTY ); if( pCom->fd != -1 ) { @@ -1289,6 +1294,8 @@ int hb_comOpen( int iPort ) pCom->status |= HB_COM_OPEN; } hb_comSetOsError( pCom, iResult == -1 ); + + hb_vmLock(); } } @@ -1957,11 +1964,13 @@ int hb_comClose( int iPort ) if( pCom ) { + hb_vmUnlock(); /* FlushFileBuffers( pCom->hComm ); */ fResult = CloseHandle( pCom->hComm ); pCom->hComm = INVALID_HANDLE_VALUE; pCom->status &= ~HB_COM_OPEN; hb_comSetOsError( pCom, !fResult ); + hb_vmLock(); } return fResult ? 0 : -1; @@ -1982,9 +1991,11 @@ int hb_comOpen( int iPort ) { char buffer[ HB_COM_DEV_NAME_MAX ]; const char * szName = hb_comGetName( pCom, buffer, sizeof( buffer ) ); - TCHAR lpName[ HB_COM_DEV_NAME_MAX ]; + LPTSTR lpName, lpFree; - HB_TCHAR_COPYTO( lpName, szName, HB_SIZEOFARRAY( lpName ) - 1 ); + lpName = HB_FSNAMECONV( szName, &lpFree ); + + hb_vmUnlock(); pCom->hComm = CreateFile( lpName, GENERIC_READ | GENERIC_WRITE, @@ -1998,6 +2009,11 @@ int hb_comOpen( int iPort ) pCom->status |= HB_COM_OPEN; } hb_comSetOsError( pCom, !fResult ); + + hb_vmLock(); + + if( lpFree ) + hb_xfree( lpFree ); } } @@ -2763,11 +2779,13 @@ int hb_comClose( int iPort ) if( pCom ) { + hb_vmUnlock(); /* DosResetBuffer( pCom->hFile ); */ rc = DosClose( pCom->hFile ); pCom->hFile = 0; pCom->status &= ~HB_COM_OPEN; hb_comSetOsError( pCom, rc ); + hb_vmLock(); } return ( rc == NO_ERROR ) ? 0 : -1; @@ -2790,6 +2808,8 @@ int hb_comOpen( int iPort ) const char * pszName = hb_comGetName( pCom, buffer, sizeof( buffer ) ); ULONG ulAction = 0; + hb_vmUnlock(); + rc = DosOpen( ( PSZ ) pszName, &pCom->hFile, &ulAction, @@ -2802,6 +2822,8 @@ int hb_comOpen( int iPort ) pCom->status |= HB_COM_OPEN; hb_comSetOsError( pCom, rc ); + + hb_vmLock(); } } @@ -3281,10 +3303,12 @@ int hb_comClose( int iPort ) if( pCom ) { + hb_vmUnlock(); COMPortClose( iPort - 1 ); pCom->status &= ~HB_COM_OPEN; hb_comSetOsError( pCom, 0 ); iResult = 0; + hb_vmLock(); } return iResult; @@ -3305,6 +3329,8 @@ int hb_comOpen( int iPort ) { int iBaud, iParity, iSize, iStop, iFlowControl; + hb_vmUnlock(); + iBaud = iParity = iSize = iStop = 0; iFlowControl = 0; s_comChkPortParam( &iBaud, &iParity, &iSize, &iStop ); @@ -3320,6 +3346,8 @@ int hb_comOpen( int iPort ) hb_comSetOsError( pCom, iResult ); iResult = -1; } + + hb_vmLock(); } } diff --git a/harbour/src/rtl/hbproces.c b/harbour/src/rtl/hbproces.c index 5999a7bb95..80581ee3db 100644 --- a/harbour/src/rtl/hbproces.c +++ b/harbour/src/rtl/hbproces.c @@ -1017,12 +1017,12 @@ int hb_fsProcessRun( const char * pszFilename, for( ;; ) { dwCount = 0; - if( nStdInLen && hStdin != FS_ERROR ) - lpHandles[ dwCount++ ] = ( HANDLE ) hb_fsGetOsHandle( hStdin ); if( hStdout != FS_ERROR ) lpHandles[ dwCount++ ] = ( HANDLE ) hb_fsGetOsHandle( hStdout ); if( hStderr != FS_ERROR ) lpHandles[ dwCount++ ] = ( HANDLE ) hb_fsGetOsHandle( hStderr ); + if( nStdInLen && hStdin != FS_ERROR ) + lpHandles[ dwCount++ ] = ( HANDLE ) hb_fsGetOsHandle( hStdin ); lpHandles[ dwCount++ ] = ( HANDLE ) hb_fsGetOsHandle( hProcess ); @@ -1110,6 +1110,13 @@ int hb_fsProcessRun( const char * pszFilename, hStdin = FS_ERROR; } + if( hStdin != FS_ERROR ) + hb_fsPipeUnblock( hStdin ); + if( hStdout != FS_ERROR ) + hb_fsPipeUnblock( hStdout ); + if( hStderr != FS_ERROR ) + hb_fsPipeUnblock( hStderr ); + for( ;; ) { fdMax = 0; @@ -1145,18 +1152,6 @@ int hb_fsProcessRun( const char * pszFilename, n = select( fdMax + 1, prfds, pwfds, NULL, NULL ); if( n > 0 ) { - if( nStdInLen && hStdin != FS_ERROR && FD_ISSET( hStdin, &wfds ) ) - { - ul = hb_fsWriteLarge( hStdin, pStdInBuf, nStdInLen ); - pStdInBuf += ul; - nStdInLen -= ul; - if( nStdInLen == 0 ) - { - hb_fsClose( hStdin ); - hStdin = FS_ERROR; - } - } - if( hStdout != FS_ERROR && FD_ISSET( hStdout, &rfds ) ) { if( nOutBuf == nOutSize ) @@ -1196,7 +1191,21 @@ int hb_fsProcessRun( const char * pszFilename, else nErrBuf += ul; } + + if( nStdInLen && hStdin != FS_ERROR && FD_ISSET( hStdin, &wfds ) ) + { + ul = hb_fsWriteLarge( hStdin, pStdInBuf, nStdInLen ); + pStdInBuf += ul; + nStdInLen -= ul; + if( nStdInLen == 0 ) + { + hb_fsClose( hStdin ); + hStdin = FS_ERROR; + } + } } + else + break; } if( hStdin != FS_ERROR )