From 43006ae7e96d282171eb7489c32f81f0d466c480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Tue, 1 Dec 2015 22:46:39 +0100 Subject: [PATCH] 2015-12-01 22:46 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rdd/dbf1.c * update DBF header only after modification in COMMIT and CLOSE methods. It's Cl*pper and xBase++ compatible behavior anyhow it also means that number of records in DBF header is not modified just after APPEND so it cannot be used to synchronization in concurrent file access. * src/rtl/hbproces.c ! safe and restore hb_fsError() when unused pipe handles are closed in hb_fsProcessOpen() ! add extension (.com or .exe) in hb_fsProcessOpen()/hb_fsProcessRun() when executed command is given with PATH part and without extension. It's documented that DosExecPgm() needs full filename in such case. It fixes problem with contrib/make.hb which calls hbmk2 with directory part but without extension. ! enabled pipes instead of temporary files for stdio redirection in OS2 builds of hb_fsProcessRun() - now it should work correctly. * src/rtl/hbprocfn.c + update FError() in hb_Proces*() functions --- ChangeLog.txt | 21 +++++++++++++ src/rdd/dbf1.c | 17 ++--------- src/rtl/hbproces.c | 75 ++++++++++++++++++++++++++++++---------------- src/rtl/hbprocfn.c | 14 +++++++-- 4 files changed, 85 insertions(+), 42 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index d32cfb7ad6..59daa2384e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,27 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2015-12-01 22:46 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/rdd/dbf1.c + * update DBF header only after modification in COMMIT and CLOSE methods. + It's Cl*pper and xBase++ compatible behavior anyhow it also means that + number of records in DBF header is not modified just after APPEND + so it cannot be used to synchronization in concurrent file access. + + * src/rtl/hbproces.c + ! safe and restore hb_fsError() when unused pipe handles are closed + in hb_fsProcessOpen() + ! add extension (.com or .exe) in hb_fsProcessOpen()/hb_fsProcessRun() + when executed command is given with PATH part and without extension. + It's documented that DosExecPgm() needs full filename in such case. + It fixes problem with contrib/make.hb which calls hbmk2 with directory + part but without extension. + ! enabled pipes instead of temporary files for stdio redirection in OS2 + builds of hb_fsProcessRun() - now it should work correctly. + + * src/rtl/hbprocfn.c + + update FError() in hb_Proces*() functions + 2015-11-30 14:56 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/hbjson.h * src/rtl/hbjson.c diff --git a/src/rdd/dbf1.c b/src/rdd/dbf1.c index 0a0c2dc576..e6c38062fe 100644 --- a/src/rdd/dbf1.c +++ b/src/rdd/dbf1.c @@ -856,7 +856,6 @@ static void hb_dbfTableCrypt( DBFAREAP pArea, PHB_ITEM pPasswd, HB_BOOL fEncrypt if( errCode == HB_SUCCESS ) { pArea->fTableEncrypted = fEncrypt; - pArea->fUpdateHeader = HB_TRUE; SELF_WRITEDBHEADER( &pArea->area ); } } @@ -2435,15 +2434,8 @@ static HB_ERRCODE hb_dbfGoCold( DBFAREAP pArea ) if( ! hb_dbfWriteRecord( pArea ) ) return HB_FAILURE; - if( pArea->fAppend ) - { - pArea->fUpdateHeader = HB_TRUE; - pArea->fAppend = HB_FALSE; - } - - /* Update header */ - if( pArea->fShared && pArea->fUpdateHeader ) - return SELF_WRITEDBHEADER( &pArea->area ); + pArea->fUpdateHeader = HB_TRUE; + pArea->fAppend = HB_FALSE; } return HB_SUCCESS; } @@ -3539,8 +3531,6 @@ static HB_ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo ) if( ! fRawBlob ) { - /* Force write new header */ - pArea->fUpdateHeader = HB_TRUE; /* Write header */ errCode = SELF_WRITEDBHEADER( &pArea->area ); if( errCode != HB_SUCCESS ) @@ -4845,8 +4835,6 @@ static HB_ERRCODE hb_dbfPack( DBFAREAP pArea ) if( pArea->ulRecCount != ulRecOut ) { pArea->ulRecCount = ulRecOut; - /* Force write new header */ - pArea->fUpdateHeader = HB_TRUE; if( SELF_WRITEDBHEADER( &pArea->area ) != HB_SUCCESS ) return HB_FAILURE; } @@ -5578,7 +5566,6 @@ static HB_ERRCODE hb_dbfZap( DBFAREAP pArea ) if( SELF_GOCOLD( &pArea->area ) != HB_SUCCESS ) return HB_FAILURE; - pArea->fUpdateHeader = HB_TRUE; pArea->ulRecCount = 0; if( SELF_WRITEDBHEADER( &pArea->area ) != HB_SUCCESS ) diff --git a/src/rtl/hbproces.c b/src/rtl/hbproces.c index 42aa36d89b..46a5f99d0d 100644 --- a/src/rtl/hbproces.c +++ b/src/rtl/hbproces.c @@ -89,7 +89,7 @@ #endif #ifndef HB_PROCESS_USEFILES -# if defined( HB_OS_DOS ) || defined( HB_OS_WIN_CE ) || defined( HB_OS_OS2 ) +# if defined( HB_OS_DOS ) || defined( HB_OS_WIN_CE ) # define HB_PROCESS_USEFILES # endif #endif @@ -98,40 +98,60 @@ static char * hb_buildArgsOS2( const char *pszFileName ) { - char * pArgs, * pszFree = NULL, cQuote = 0; - HB_SIZE nLen; + PHB_FNAME pFilepath; + char szFileBuf[ HB_PATH_MAX ]; + char * pArgs, * pszFree = NULL, cQuote = 0, c; + HB_SIZE nLen = 0, nLen2; while( HB_ISSPACE( *pszFileName ) ) ++pszFileName; pszFileName = hb_osEncodeCP( pszFileName, &pszFree, NULL ); - nLen = strlen( pszFileName ); - pArgs = ( char * ) hb_xgrab( nLen + 2 ); - memcpy( pArgs, pszFileName, nLen + 1 ); - pArgs[ nLen + 1 ] = '\0'; + while( ( c = *pszFileName ) != '\0' ) + { + ++pszFileName; + if( c == '"' ) + cQuote = cQuote ? 0 : c; + else + { + if( cQuote == 0 && HB_ISSPACE( c ) ) + break; + if( nLen < sizeof( szFileBuf ) - 1 ) + szFileBuf[ nLen++ ] = c; + } + } + szFileBuf[ nLen ] = '\0'; + + while( HB_ISSPACE( *pszFileName ) ) + ++pszFileName; + nLen2 = strlen( pszFileName ); + + pFilepath = hb_fsFNameSplit( szFileBuf ); + if( pFilepath->szPath && ! pFilepath->szExtension ) + { + pFilepath->szExtension = ".com"; + if( ! hb_fsFileExists( hb_fsFNameMerge( szFileBuf, pFilepath ) ) ) + { + pFilepath->szExtension = ".exe"; + if( ! hb_fsFileExists( hb_fsFNameMerge( szFileBuf, pFilepath ) ) ) + { + pFilepath->szExtension = NULL; + hb_fsFNameMerge( szFileBuf, pFilepath ); + } + } + nLen = strlen( szFileBuf ); + } + hb_xfree( pFilepath ); + + pArgs = ( char * ) hb_xgrab( nLen + nLen2 + 3 ); + memcpy( pArgs, szFileBuf, nLen + 1 ); + memcpy( pArgs + nLen + 1, pszFileName, nLen2 + 1 ); + pArgs[ nLen + nLen2 + 2 ] = '\0'; if( pszFree ) hb_xfree( pszFree ); - pszFree = pArgs; - while( *pszFree ) - { - if( *pszFree == cQuote ) - cQuote = 0; - else if( cQuote == 0 ) - { - if( *pszFree == '"' ) - cQuote = *pszFree; - else if( HB_ISSPACE( *pszFree ) ) - { - *pszFree = '\0'; - break; - } - } - ++pszFree; - } - return pArgs; } @@ -447,6 +467,7 @@ HB_FHANDLE hb_fsProcessOpen( const char * pszFileName, hPipeOut[ 2 ] = { FS_ERROR, FS_ERROR }, hPipeErr[ 2 ] = { FS_ERROR, FS_ERROR }; HB_FHANDLE hResult = FS_ERROR; + HB_ERRCODE errCode; HB_BOOL fError = HB_FALSE; HB_TRACE( HB_TR_DEBUG, ( "hb_fsProcessOpen(%s, %p, %p, %p, %d, %p)", pszFileName, phStdin, phStdout, phStderr, fDetach, pulPID ) ); @@ -874,6 +895,8 @@ HB_FHANDLE hb_fsProcessOpen( const char * pszFileName, #endif } + errCode = hb_fsError(); + if( hPipeIn[ 0 ] != FS_ERROR ) hb_fsClose( hPipeIn[ 0 ] ); if( hPipeIn[ 1 ] != FS_ERROR ) @@ -890,6 +913,8 @@ HB_FHANDLE hb_fsProcessOpen( const char * pszFileName, hb_fsClose( hPipeErr[ 1 ] ); } + hb_fsSetError( errCode ); + return hResult; } diff --git a/src/rtl/hbprocfn.c b/src/rtl/hbprocfn.c index 39ef6fd851..1e958f2a79 100644 --- a/src/rtl/hbprocfn.c +++ b/src/rtl/hbprocfn.c @@ -78,6 +78,7 @@ HB_FUNC( HB_PROCESSOPEN ) hProcess = hb_fsProcessOpen( szName, phStdIn, phStdOut, phStdErr, fDetach, &ulPID ); + hb_fsSetFError( hb_fsError() ); if( hProcess != FS_ERROR ) { if( phStdIn ) @@ -99,7 +100,11 @@ HB_FUNC( HB_PROCESSVALUE ) HB_FHANDLE hProcess = hb_numToHandle( hb_parnint( 1 ) ); if( hProcess != 0 && hProcess != FS_ERROR && ( hb_pcount() < 2 || HB_ISLOG( 2 ) ) ) - hb_retni( hb_fsProcessValue( hProcess, hb_pcount() < 2 || hb_parl( 2 ) ) ); + { + int iResult = hb_fsProcessValue( hProcess, hb_pcount() < 2 || hb_parl( 2 ) ); + hb_fsSetFError( hb_fsError() ); + hb_retni( iResult ); + } else hb_errRT_BASE_SubstR( EG_ARG, 4001, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } @@ -109,7 +114,11 @@ HB_FUNC( HB_PROCESSCLOSE ) HB_FHANDLE hProcess = hb_numToHandle( hb_parnint( 1 ) ); if( hProcess != 0 && hProcess != FS_ERROR && ( hb_pcount() < 2 || HB_ISLOG( 2 ) ) ) - hb_retl( hb_fsProcessClose( hProcess, hb_pcount() < 2 || hb_parl( 2 ) ) ); + { + HB_BOOL fResult = hb_fsProcessClose( hProcess, hb_pcount() < 2 || hb_parl( 2 ) ); + hb_fsSetFError( hb_fsError() ); + hb_retl( fResult ); + } else hb_errRT_BASE_SubstR( EG_ARG, 4001, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } @@ -143,6 +152,7 @@ HB_FUNC( HB_PROCESSRUN ) iResult = hb_fsProcessRun( szName, szStdIn, hb_parclen( 2 ), pStdOutPtr, &nStdOut, pStdErrPtr, &nStdErr, fDetach ); + hb_fsSetFError( hb_fsError() ); if( pStdOutBuf ) {