2008-10-02 14:33 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/include/hbstack.h
    % enable assembler inline function to access HVM thread stack pointer
      without native compiler TLS support even if HB_STACK_PRELOAD is not
      defined in MinGW builds. It gives some additional small speed
      improvement in MT mode

  * harbour/source/rtl/idle.c
    * unlock HVM inside hb_releaseCPU() function

  * harbour/contrib/hbwin/win_ole.c
    ! fixed casting and C++ compilation in some compilers

  * harbour/include/Makefile
  + harbour/contrib/examples/rdddbt/hbrdddbt.h
  - harbour/include/hbrdddbt.h
    ! moved hbrdddbt.h to correct location

  * harbour/include/Makefile
    ! added missinf hbthread.h

  * harbour/tests/rddtest/rddmktst.prg
  * harbour/tests/rddtest/adscl52.prg
  * harbour/tests/rddtest/adscl53.prg
  * harbour/tests/rddtest/ntxcl52.prg
  * harbour/tests/rddtest/ntxcl53.prg
  * harbour/tests/rddtest/cdxcl52.prg
  * harbour/tests/rddtest/rddtst.prg
  * harbour/tests/rddtest/cdxcl53.prg
    ! fixed description in header I wrongly copied without updating
      from other files

  + harbour/tests/hsxtest.prg
    + added test code for HiPer-SEEK indexes

  * harbour/source/rtl/filesys.c
    + added new functions: hb_fsExtName(), hb_fsReadAt(), hb_fsWriteAt(),
      hb_fsTruncAt() to use with shared file handles.
      Please test it in other *nixes. I used pread[64]()/pwrite[64]()
      POSIX functions but I do not know if they are available by default
      in other supported platforms like MacOSX, BSD, HPUX, SunOS.
      If not they I will have to implement some workaround.

  * harbour/common.mak
  * harbour/source/rtl/Makefile
  * harbour/include/hbapifs.h
  + harbour/source/rtl/filebuf.c
    + added set of new file functions (hb_file*()) which are designed to
      use with shared file handles and locks (buffers in the future):
      hb_fileExtOpen(), hb_fileCreateTemp(), hb_fileClose(), hb_fileLock(),
      hb_fileReadAt(), hb_fileWriteAt(), hb_fileTruncAt(), hb_fileSize(),
      hb_fileCommit(), hb_fileHandle()
      These functions operate on PHB_FILE structure instead of HB_FHANDLE.
      Now in POSIX systems they share file handle between aliased or
      simultaneously open by other thread work areas. It resolves the
      problem with releasing all process FCNTL locks by any close()
      operation even on duplicated or open() separately handle.
      Now DOS deny flags emulation works in single process even if
      BSD locks are disabled (non Linux *nixes).
      They also keep internal file lock list what allows to synchronize
      threads and aliases with file locks in POSIX systems. In the future
      it will be used also for internal locking to synchronize threads
      without OS level locks - pseudo exclusive mode in cloned WA.
      Finally these structures will be used also for file buffers
      which will be shared between aliased WA and threads.

  * harbour/include/hbrdddbf.h
  * harbour/include/hbrddcdx.h
  * harbour/include/hbrddntx.h
  * harbour/include/hbrdddel.h
  * harbour/include/hbrddsdf.h
  * harbour/source/rdd/dbf1.c
  * harbour/source/rdd/delim1.c
  * harbour/source/rdd/sdf1.c
  * harbour/source/rdd/dbffpt/dbffpt1.c
  * harbour/source/rdd/dbfntx/dbfntx1.c
  * harbour/source/rdd/dbfcdx/dbfcdx1.c
  * harbour/source/rdd/hsx/hsx.c
  * harbour/contrib/hbbmcdx/bmdbfcdx.c
  * harbour/contrib/hbbmcdx/hbbmcdx.h
    * use PHB_FILE and hb_file*() functions instead of HB_FHANDLE (hb_fs*())
      to access files.

  + harbour/tests/aliaslck.prg
    + added test code for file lock synchronization between aliased
      work areas
This commit is contained in:
Przemyslaw Czerpak
2008-10-02 12:34:36 +00:00
parent 693f75900d
commit ffd9b480a4
35 changed files with 1942 additions and 983 deletions

View File

@@ -8,6 +8,93 @@
2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
*/
2008-10-02 14:33 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbstack.h
% enable assembler inline function to access HVM thread stack pointer
without native compiler TLS support even if HB_STACK_PRELOAD is not
defined in MinGW builds. It gives some additional small speed
improvement in MT mode
* harbour/source/rtl/idle.c
* unlock HVM inside hb_releaseCPU() function
* harbour/contrib/hbwin/win_ole.c
! fixed casting and C++ compilation in some compilers
* harbour/include/Makefile
+ harbour/contrib/examples/rdddbt/hbrdddbt.h
- harbour/include/hbrdddbt.h
! moved hbrdddbt.h to correct location
* harbour/include/Makefile
! added missinf hbthread.h
* harbour/tests/rddtest/rddmktst.prg
* harbour/tests/rddtest/adscl52.prg
* harbour/tests/rddtest/adscl53.prg
* harbour/tests/rddtest/ntxcl52.prg
* harbour/tests/rddtest/ntxcl53.prg
* harbour/tests/rddtest/cdxcl52.prg
* harbour/tests/rddtest/rddtst.prg
* harbour/tests/rddtest/cdxcl53.prg
! fixed description in header I wrongly copied without updating
from other files
+ harbour/tests/hsxtest.prg
+ added test code for HiPer-SEEK indexes
* harbour/source/rtl/filesys.c
+ added new functions: hb_fsExtName(), hb_fsReadAt(), hb_fsWriteAt(),
hb_fsTruncAt() to use with shared file handles.
Please test it in other *nixes. I used pread[64]()/pwrite[64]()
POSIX functions but I do not know if they are available by default
in other supported platforms like MacOSX, BSD, HPUX, SunOS.
If not they I will have to implement some workaround.
* harbour/common.mak
* harbour/source/rtl/Makefile
* harbour/include/hbapifs.h
+ harbour/source/rtl/filebuf.c
+ added set of new file functions (hb_file*()) which are designed to
use with shared file handles and locks (buffers in the future):
hb_fileExtOpen(), hb_fileCreateTemp(), hb_fileClose(), hb_fileLock(),
hb_fileReadAt(), hb_fileWriteAt(), hb_fileTruncAt(), hb_fileSize(),
hb_fileCommit(), hb_fileHandle()
These functions operate on PHB_FILE structure instead of HB_FHANDLE.
Now in POSIX systems they share file handle between aliased or
simultaneously open by other thread work areas. It resolves the
problem with releasing all process FCNTL locks by any close()
operation even on duplicated or open() separately handle.
Now DOS deny flags emulation works in single process even if
BSD locks are disabled (non Linux *nixes).
They also keep internal file lock list what allows to synchronize
threads and aliases with file locks in POSIX systems. In the future
it will be used also for internal locking to synchronize threads
without OS level locks - pseudo exclusive mode in cloned WA.
Finally these structures will be used also for file buffers
which will be shared between aliased WA and threads.
* harbour/include/hbrdddbf.h
* harbour/include/hbrddcdx.h
* harbour/include/hbrddntx.h
* harbour/include/hbrdddel.h
* harbour/include/hbrddsdf.h
* harbour/source/rdd/dbf1.c
* harbour/source/rdd/delim1.c
* harbour/source/rdd/sdf1.c
* harbour/source/rdd/dbffpt/dbffpt1.c
* harbour/source/rdd/dbfntx/dbfntx1.c
* harbour/source/rdd/dbfcdx/dbfcdx1.c
* harbour/source/rdd/hsx/hsx.c
* harbour/contrib/hbbmcdx/bmdbfcdx.c
* harbour/contrib/hbbmcdx/hbbmcdx.h
* use PHB_FILE and hb_file*() functions instead of HB_FHANDLE (hb_fs*())
to access files.
+ harbour/tests/aliaslck.prg
+ added test code for file lock synchronization between aliased
work areas
2008-10-02 11:49 UTC+0200 Viktor Szakats (harbour.01 syenar hu)
* source/vm/extrap.c
* Added "error" text in exception message.

View File

@@ -474,6 +474,7 @@ RTL_LIB_OBJS = \
$(OBJ_DIR)\errorapu$(OBJEXT) \
$(OBJ_DIR)\errorint$(OBJEXT) \
$(OBJ_DIR)\file$(OBJEXT) \
$(OBJ_DIR)\filebuf$(OBJEXT) \
$(OBJ_DIR)\filehb$(OBJEXT) \
$(OBJ_DIR)\filesys$(OBJEXT) \
$(OBJ_DIR)\fkmax$(OBJEXT) \

View File

@@ -1073,7 +1073,7 @@ static void hb_cdxIndexCheckBuffers( LPCDXINDEX pIndex )
*/
static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader )
{
HB_FHANDLE hFile = pIndex->hFile;
PHB_FILE pFile = pIndex->pFile;
BYTE byBuf[4];
ULONG ulPos;
@@ -1098,8 +1098,7 @@ static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader )
}
else
{
if ( hb_fsSeekLarge( hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos ||
hb_fsRead( hFile, (BYTE *) byBuf, 4 ) != 4 )
if ( hb_fileReadAt( pFile, (BYTE *) byBuf, 4, ulPos ) != 4 )
hb_errInternal( EDBF_READ, "hb_cdxIndexGetAvailPage: Read index page failed.", NULL, NULL );
pIndex->freePage = HB_GET_LE_UINT32( byBuf );
#ifdef HB_CDX_DBGUPDT
@@ -1114,21 +1113,22 @@ static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader )
if ( pIndex->nextAvail != CDX_DUMMYNODE )
ulPos = pIndex->nextAvail;
else
ulPos = ( ULONG ) hb_fsSeekLarge( hFile, 0, FS_END );
ulPos = ( ULONG ) hb_fileSize( pFile );
pIndex->nextAvail = ulPos + iCnt * CDX_PAGELEN;
/* TODO: ### */
if ( bHeader )
{
BYTE byBuf[CDX_PAGELEN];
HB_FOFFSET fOffset = ulPos;
memset( byBuf, 0, CDX_PAGELEN );
if ( hb_fsSeekLarge( hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos )
hb_errInternal( EDBF_WRITE, "Write in index page failed.(1)", NULL, NULL );
while ( iCnt-- )
do
{
if ( hb_fsWrite( hFile, byBuf, CDX_PAGELEN ) != CDX_PAGELEN )
hb_errInternal( EDBF_WRITE, "Write in index page failed.(2)", NULL, NULL );
if( hb_fileWriteAt( pFile, byBuf, CDX_PAGELEN, fOffset ) != CDX_PAGELEN )
hb_errInternal( EDBF_WRITE, "Write in index page failed.", NULL, NULL );
fOffset += CDX_PAGELEN;
}
while( --iCnt );
pIndex->fChanged = TRUE;
}
}
@@ -1187,8 +1187,7 @@ static void hb_cdxIndexFlushAvailPage( LPCDXINDEX pIndex )
fClean = FALSE;
}
HB_PUT_LE_UINT32( byPageBuf, pLst->ulAddr );
if ( hb_fsSeekLarge( pIndex->hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos ||
hb_fsWrite( pIndex->hFile, byPageBuf, CDX_PAGELEN ) != CDX_PAGELEN )
if( hb_fileWriteAt( pIndex->pFile, byPageBuf, CDX_PAGELEN, ulPos ) != CDX_PAGELEN )
{
hb_errInternal( EDBF_WRITE, "Write in index page failed.", NULL, NULL );
}
@@ -1223,13 +1222,12 @@ static void hb_cdxIndexDropAvailPage( LPCDXINDEX pIndex )
static void hb_cdxIndexPageWrite( LPCDXINDEX pIndex, ULONG ulPos, BYTE * pBuffer,
USHORT uiSize )
{
if ( pIndex->fReadonly )
if( pIndex->fReadonly )
hb_errInternal( 9101, "hb_cdxIndexPageWrite on readonly database.", NULL, NULL );
if ( pIndex->fShared && !pIndex->lockWrite )
if( pIndex->fShared && !pIndex->lockWrite )
hb_errInternal( 9102, "hb_cdxIndexPageWrite on not locked index file.", NULL, NULL );
if ( hb_fsSeekLarge( pIndex->hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos ||
hb_fsWrite( pIndex->hFile, pBuffer, uiSize ) != uiSize )
if( hb_fileWriteAt( pIndex->pFile, pBuffer, uiSize, ulPos ) != ( ULONG ) uiSize )
hb_errInternal( EDBF_WRITE, "Write in index page failed.", NULL, NULL );
pIndex->fChanged = TRUE;
#ifdef HB_CDX_DBGUPDT
@@ -1243,11 +1241,10 @@ static void hb_cdxIndexPageWrite( LPCDXINDEX pIndex, ULONG ulPos, BYTE * pBuffer
static void hb_cdxIndexPageRead( LPCDXINDEX pIndex, ULONG ulPos, BYTE * pBuffer,
USHORT uiSize )
{
if ( pIndex->fShared && !( pIndex->lockRead || pIndex->lockWrite ) )
if( pIndex->fShared && !( pIndex->lockRead || pIndex->lockWrite ) )
hb_errInternal( 9103, "hb_cdxIndexPageRead on not locked index file.", NULL, NULL );
if ( hb_fsSeekLarge( pIndex->hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos ||
hb_fsRead( pIndex->hFile, pBuffer, uiSize ) != uiSize )
if( hb_fileReadAt( pIndex->pFile, pBuffer, uiSize, ulPos ) != ( ULONG ) uiSize )
hb_errInternal( EDBF_READ, "hb_cdxIndexPageRead: Read index page failed.", NULL, NULL );
#ifdef HB_CDX_DBGUPDT
cdxReadNO++;
@@ -1262,10 +1259,9 @@ static void hb_cdxIndexCheckVersion( LPCDXINDEX pIndex )
BYTE byBuf[8];
ULONG ulVer, ulFree;
if ( hb_fsSeek( pIndex->hFile, 0x04, FS_SET ) != 0x04 ||
hb_fsRead( pIndex->hFile, byBuf, 8 ) != 8 )
if( hb_fileReadAt( pIndex->pFile, byBuf, 8, 0x04 ) != 8 )
{
if ( pIndex->lockWrite > 0 && hb_fsSeek( pIndex->hFile, 0, FS_END ) == 0 )
if( pIndex->lockWrite > 0 && hb_fileSize( pIndex->pFile ) == 0 )
memset( byBuf, 0, 8 );
else
hb_errInternal( 2155, "hb_cdxIndexCheckVersion: Read error on index heading page.", NULL, NULL );
@@ -1319,7 +1315,7 @@ static BOOL hb_cdxIndexLockRead( LPCDXINDEX pIndex )
}
else
{
ret = hb_dbfLockIdxFile( pIndex->hFile, pIndex->pArea->bLockType,
ret = hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType,
FL_LOCK | FLX_SHARED | FLX_WAIT, &pIndex->ulLockPos );
if ( !ret )
hb_cdxErrorRT( pIndex->pArea, EG_LOCK, EDBF_LOCK, pIndex->szFileName, hb_fsError(), 0 );
@@ -1362,7 +1358,7 @@ static BOOL hb_cdxIndexLockWrite( LPCDXINDEX pIndex )
hb_errInternal( 9107, "hb_cdxIndexLockWrite: lock failure (*)", NULL, NULL );
pIndex->WrLck = TRUE;
#endif
ret = hb_dbfLockIdxFile( pIndex->hFile, pIndex->pArea->bLockType,
ret = hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType,
FL_LOCK | FLX_EXCLUSIVE | FLX_WAIT, &pIndex->ulLockPos );
}
if ( !ret )
@@ -1415,7 +1411,7 @@ static BOOL hb_cdxIndexUnLockRead( LPCDXINDEX pIndex )
hb_errInternal( 9108, "hb_cdxIndexUnLockRead: unlock error (*)", NULL, NULL );
pIndex->RdLck = FALSE;
#endif
if ( !hb_dbfLockIdxFile( pIndex->hFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) )
if ( !hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) )
{
hb_errInternal( 9108, "hb_cdxIndexUnLockRead: unlock error.", NULL, NULL );
}
@@ -1456,8 +1452,7 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex )
(pIndex->ulVersion)++;
HB_PUT_LE_UINT32( &byBuf[0], pIndex->freePage );
HB_PUT_BE_UINT32( &byBuf[4], pIndex->ulVersion );
if ( hb_fsSeek( pIndex->hFile, 0x04, FS_SET ) != 0x04 ||
hb_fsWrite( pIndex->hFile, byBuf, 8) != 8 )
if( hb_fileWriteAt( pIndex->pFile, byBuf, 8, 0x04 ) != 8 )
{
hb_errInternal( EDBF_WRITE, "Write in index page failed (ver)", NULL, NULL );
}
@@ -1469,7 +1464,7 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex )
hb_errInternal( 9108, "hb_cdxIndexUnLockWrite: unlock error (*)", NULL, NULL );
pIndex->WrLck = FALSE;
#endif
if ( !hb_dbfLockIdxFile( pIndex->hFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) )
if ( !hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) )
{
hb_errInternal( 9108, "hb_cdxIndexUnLockWrite: unlock error.", NULL, NULL );
}
@@ -1480,8 +1475,7 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex )
{
BYTE byBuf[4];
HB_PUT_LE_UINT32( &byBuf[0], pIndex->freePage );
if ( hb_fsSeek( pIndex->hFile, 0x04, FS_SET ) != 0x04 ||
hb_fsWrite( pIndex->hFile, byBuf, 4) != 4 )
if( hb_fileWriteAt( pIndex->pFile, byBuf, 4, 0x04 ) != 4 )
{
hb_errInternal( EDBF_WRITE, "Write in index page failed (ver.ex)", NULL, NULL );
}
@@ -3537,7 +3531,7 @@ static void hb_cdxTagLoad( LPCDXTAG pTag )
* invalid key value length
*/
if( pTag->RootBlock == 0 || pTag->RootBlock % CDX_PAGELEN != 0 ||
( HB_FOFFSET ) pTag->RootBlock >= hb_fsSeekLarge( pTag->pIndex->hFile, 0, FS_END ) ||
( HB_FOFFSET ) pTag->RootBlock >= hb_fileSize( pTag->pIndex->pFile ) ||
HB_GET_LE_UINT16( tagHeader.keySize ) > CDX_MAXKEY ||
uiForPos + uiForLen > CDX_HEADEREXPLEN ||
uiKeyPos + uiKeyLen > CDX_HEADEREXPLEN ||
@@ -4730,8 +4724,7 @@ static void hb_cdxIndexReindex( LPCDXINDEX pIndex )
pIndex->ulVersion = 0;
pIndex->nextAvail = 0;
pIndex->freePage = 0;
hb_fsSeek( pIndex->hFile, 0, FS_SET );
hb_fsWrite( pIndex->hFile, NULL, 0 );
hb_fileTruncAt( pIndex->pFile, 0 );
pIndex->fChanged = TRUE;
/* Rebuild the compound (master) tag */
@@ -4764,7 +4757,7 @@ static LPCDXINDEX hb_cdxIndexNew( CDXAREAP pArea )
pIndex = ( LPCDXINDEX ) hb_xgrab( sizeof( CDXINDEX ) );
memset( pIndex, 0, sizeof( CDXINDEX ) );
pIndex->hFile = FS_ERROR;
pIndex->pFile = NULL;
pIndex->pArea = pArea;
pIndex->nextAvail = CDX_DUMMYNODE;
return pIndex;
@@ -4804,9 +4797,9 @@ static void hb_cdxIndexFree( LPCDXINDEX pIndex )
hb_cdxIndexFreeTags( pIndex );
/* Close file */
if( pIndex->hFile != FS_ERROR )
if( pIndex->pFile )
{
hb_fsClose( pIndex->hFile );
hb_fileClose( pIndex->pFile );
if( pIndex->fDelete )
{
hb_fsDelete( ( BYTE * ) ( pIndex->szRealName ?
@@ -7309,9 +7302,9 @@ static ERRCODE hb_cdxFlush( CDXAREAP pArea )
pIndex = pArea->lpIndexes;
while ( pIndex )
{
if ( pIndex->hFile != FS_ERROR && pIndex->fFlush )
if ( pIndex->pFile && pIndex->fFlush )
{
hb_fsCommit( pIndex->hFile );
hb_fileCommit( pIndex->pFile );
pIndex->fFlush = FALSE;
}
pIndex = pIndex->pNext;
@@ -7747,7 +7740,7 @@ static ERRCODE hb_cdxZap ( CDXAREAP pArea )
static ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo )
{
USHORT uiFlags;
HB_FHANDLE hFile;
PHB_FILE pFile;
char szBaseName[ CDX_MAXTAGNAMELEN + 1 ];
char szFileName[ _POSIX_PATH_MAX + 1 ];
LPCDXINDEX pIndex, * pIndexPtr;
@@ -7785,33 +7778,33 @@ static ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo )
( pArea->fShared ? FO_DENYNONE : FO_EXCLUSIVE );
do
{
hFile = hb_fsExtOpen( ( BYTE * ) szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
if( hFile == FS_ERROR )
pFile = hb_fileExtOpen( ( BYTE * ) szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
if( !pFile )
bRetry = ( hb_cdxErrorRT( pArea, EG_OPEN, EDBF_OPEN_INDEX, szFileName,
hb_fsError(), EF_CANRETRY | EF_CANDEFAULT ) == E_RETRY );
else
{
if( hb_fsSeekLarge( hFile, 0, FS_END ) <= ( HB_FOFFSET ) sizeof( CDXTAGHEADER ) )
if( hb_fileSize( pFile ) <= ( HB_FOFFSET ) sizeof( CDXTAGHEADER ) )
{
hb_fsClose( hFile );
hFile = FS_ERROR;
hb_fileClose( pFile );
pFile = NULL;
hb_cdxErrorRT( pArea, EG_CORRUPTION, EDBF_CORRUPT,
szFileName, hb_fsError(), EF_CANDEFAULT );
}
bRetry = FALSE;
}
} while ( bRetry );
} while( bRetry );
if ( hFile == FS_ERROR )
if( !pFile )
{
return FAILURE;
}
pIndex = hb_cdxIndexNew( pArea );
pIndex->hFile = hFile;
pIndex->pFile = pFile;
pIndex->fShared = pArea->fShared;
pIndex->fReadonly = pArea->fReadonly;
pIndex->szFileName = hb_strdup( szFileName );
@@ -8143,40 +8136,40 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo
if ( !fOpenedIndex )
{
HB_FHANDLE hFile;
PHB_FILE pFile;
BOOL bRetry, fShared = pArea->fShared && !fTemporary && !fExclusive;
do
{
if( fTemporary )
{
hFile = hb_fsCreateTemp( NULL, NULL, FC_NORMAL, ( BYTE * ) szTempFile );
pFile = hb_fileCreateTemp( NULL, NULL, FC_NORMAL, ( BYTE * ) szTempFile );
fNewFile = TRUE;
}
else
{
hFile = hb_fsExtOpen( ( BYTE * ) szFileName, NULL, FO_READWRITE |
( fShared ? FO_DENYNONE : FO_EXCLUSIVE ) |
( fNewFile ? FXO_TRUNCATE : FXO_APPEND ) |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
pFile = hb_fileExtOpen( ( BYTE * ) szFileName, NULL, FO_READWRITE |
( fShared ? FO_DENYNONE : FO_EXCLUSIVE ) |
( fNewFile ? FXO_TRUNCATE : FXO_APPEND ) |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
}
if( hFile == FS_ERROR )
if( !pFile )
bRetry = ( hb_cdxErrorRT( pArea, EG_CREATE, EDBF_CREATE, szFileName,
hb_fsError(), EF_CANRETRY | EF_CANDEFAULT ) == E_RETRY );
else
{
bRetry = FALSE;
if ( !fNewFile )
fNewFile = ( hb_fsSeekLarge( hFile, 0, FS_END ) == 0 );
if( !fNewFile )
fNewFile = ( hb_fileSize( pFile ) == 0 );
}
}
while ( bRetry );
while( bRetry );
if ( hFile != FS_ERROR )
if( pFile )
{
pIndex = hb_cdxIndexNew( pArea );
pIndex->hFile = hFile;
pIndex->pFile = pFile;
pIndex->fShared = fShared;
pIndex->fReadonly = FALSE;
pIndex->szFileName = hb_strdup( szFileName );
@@ -8192,8 +8185,8 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo
/* TODO: What should be default? */
/*
hb_cdxIndexFree( pIndex );
hb_fsClose( hFile );
hFile = FS_ERROR;
hb_fileClose( pFile );
pFile = NULL;
hb_cdxErrorRT( pArea, EG_CORRUPTION, EDBF_CORRUPT,
szFileName, hb_fsError(), EF_CANDEFAULT );
*/
@@ -8203,7 +8196,7 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo
}
}
if ( hFile == FS_ERROR )
if( !pFile )
{
hb_vmDestroyBlockOrMacro( pKeyExp );
if ( pForExp != NULL )
@@ -8222,8 +8215,7 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo
if ( fNewFile )
{
hb_fsSeek( pIndex->hFile, 0, FS_SET );
hb_fsWrite( pIndex->hFile, NULL, 0 );
hb_fileTruncAt( pIndex->pFile, 0 );
pIndex->fChanged = TRUE;
hb_cdxIndexDropAvailPage( pIndex );
if ( pIndex->pCompound != NULL )
@@ -8734,7 +8726,8 @@ static ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO pI
break;
case DBOI_FILEHANDLE:
pInfo->itmResult = hb_itemPutNInt( pInfo->itmResult, ( HB_NHANDLE ) ( pTag ? pTag->pIndex->hFile : FS_ERROR ) );
pInfo->itmResult = hb_itemPutNInt( pInfo->itmResult, ( HB_NHANDLE )
( pTag ? hb_fileHandle( pTag->pIndex->pFile ) : FS_ERROR ) );
break;
case DBOI_ISCOND:
@@ -10065,11 +10058,10 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex )
iRec = ulRecCount - ulRecNo + 1;
if( ulNextCount > 0 && ulNextCount < ( ULONG ) iRec )
iRec = ( int ) ulNextCount;
hb_fsSeekLarge( pArea->hDataFile,
( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen, FS_SET );
hb_fsReadLarge( pArea->hDataFile, pSort->pRecBuff, pArea->uiRecordLen * iRec );
hb_fileReadAt( pArea->pDataFile, pSort->pRecBuff, pArea->uiRecordLen * iRec,
( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen );
iRecBuff = 0;
}
pArea->pRecord = pSort->pRecBuff + iRecBuff * pArea->uiRecordLen;

View File

@@ -373,7 +373,7 @@ typedef struct _CDXINDEX
{
char * szFileName; /* Name of index file */
char * szRealName; /* Real name of index file */
HB_FHANDLE hFile; /* Index file handle */
PHB_FILE pFile; /* Index file handle */
struct _CDXAREA * pArea; /* Parent WorkArea */
struct _CDXINDEX * pNext; /* The next index in the list */
LPCDXTAG pCompound; /* Compound tag */
@@ -481,9 +481,9 @@ typedef struct _CDXAREA
* example.
*/
HB_FHANDLE hDataFile; /* Data file handle */
HB_FHANDLE hMemoFile; /* Memo file handle */
HB_FHANDLE hMemoTmpFile; /* Memo temporary file handle */
PHB_FILE pDataFile; /* Data file handle */
PHB_FILE pMemoFile; /* Memo file handle */
PHB_FILE pMemoTmpFile; /* Memo temporary file handle */
char * szDataFileName; /* Name of data file */
char * szMemoFileName; /* Name of memo file */
USHORT uiHeaderLen; /* Size of header */

View File

@@ -74,6 +74,7 @@
#include <windows.h>
#include <ole2.h>
#include <oleauto.h>
#include <olectl.h>
#ifndef __MINGW32__
/* Missing in Mingw V 2. */
@@ -1419,15 +1420,16 @@ HB_FUNC( CREATEOLEOBJECT ) /* ( cOleName | cCLSID [, cIID ] [, cLicense ] ) */
{
if( ISCHAR( 3 ) )
{
IClassFactory2 * pCF;
LPVOID * pCFPtr = NULL;
s_nOleError = CoGetClassObject( HB_ID_REF( REFCLSID, ClassID ), CLSCTX_SERVER, NULL, (LPIID) &IID_IClassFactory2, (LPVOID *) &pCF );
s_nOleError = CoGetClassObject( HB_ID_REF( REFCLSID, ClassID ), CLSCTX_SERVER, NULL, HB_ID_REF( REFIID, IID_IClassFactory2 ), pCFPtr );
if( SUCCEEDED( s_nOleError ) )
{
IClassFactory2 * pCF = ( IClassFactory2 * ) pCFPtr;
BSTR bstrLic = hb_oleAnsiToSysString( hb_parc( 3 ) );
s_nOleError = pCF->lpVtbl->CreateInstanceLic( pCF, NULL, NULL, riid, bstrLic, &pDisp );
s_nOleError = pCF->lpVtbl->CreateInstanceLic( pCF, NULL, NULL, (REFIID) riid, bstrLic, &pDisp );
SysFreeString( bstrLic );
pCF->lpVtbl->Release( pCF );

View File

@@ -38,7 +38,6 @@ C_HEADERS=\
hbpp.h \
hbrddcdx.h \
hbrdddbf.h \
hbrdddbt.h \
hbrddfpt.h \
hbrdddel.h \
hbrddntx.h \
@@ -48,6 +47,7 @@ C_HEADERS=\
hbsetup.h \
hbstack.h \
hbsxfunc.h \
hbthread.h \
hbtrace.h \
hbtypes.h \
hbver.h \

View File

@@ -173,6 +173,8 @@ extern HB_EXPORT BOOL hb_fsIsDirectory( BYTE * pFilename );
extern HB_EXPORT HB_FOFFSET hb_fsFSize ( BYTE * pszFileName, BOOL bUseDirEntry ); /* determine the size of a file */
extern HB_EXPORT HB_FHANDLE hb_fsExtOpen ( BYTE * pszFileName, BYTE * pDefExt,
USHORT uiFlags, BYTE * pPaths, PHB_ITEM pError ); /* open a file using default extension and a list of paths */
extern HB_EXPORT BYTE * hb_fsExtName ( BYTE * pFilename, BYTE * pDefExt,
USHORT uiExFlags, BYTE * pPaths ); /* convert file name for hb_fsExtOpen, caller must free the returned buffer */
extern HB_EXPORT USHORT hb_fsIsDrv ( BYTE nDrive ); /* determine if a drive number is a valid drive */
extern HB_EXPORT BOOL hb_fsIsDevice ( HB_FHANDLE hFileHandle ); /* determine if a file is attached to a device (console?) */
extern HB_EXPORT BOOL hb_fsLock ( HB_FHANDLE hFileHandle, ULONG ulStart, ULONG ulLength, USHORT uiMode ); /* request a lock on a portion of a file */
@@ -182,6 +184,7 @@ extern HB_EXPORT BOOL hb_fsMkDir ( BYTE * pszDirName ); /* create a d
extern HB_EXPORT HB_FHANDLE hb_fsOpen ( BYTE * pszFileName, USHORT uiFlags ); /* open a file */
extern HB_EXPORT USHORT hb_fsRead ( HB_FHANDLE hFileHandle, BYTE * pBuff, USHORT ulCount ); /* read contents of a file into a buffer (<=64K) */
extern HB_EXPORT ULONG hb_fsReadLarge ( HB_FHANDLE hFileHandle, BYTE * pBuff, ULONG ulCount ); /* read contents of a file into a buffer (>64K) */
extern HB_EXPORT ULONG hb_fsReadAt ( HB_FHANDLE hFileHandle, BYTE * pBuff, ULONG ulCount, HB_FOFFSET llOffset ); /* read from given offset contents of a file into a buffer (>64K) */
extern HB_EXPORT BOOL hb_fsRmDir ( BYTE * pszDirName ); /* remove a directory */
extern HB_EXPORT BOOL hb_fsRename ( BYTE * pszOldName, BYTE * pszNewName ); /* rename a file */
extern HB_EXPORT ULONG hb_fsSeek ( HB_FHANDLE hFileHandle, LONG lOffset, USHORT uiMode ); /* reposition an open file */
@@ -194,8 +197,10 @@ extern HB_EXPORT BOOL hb_fsGetAttr ( BYTE * pszFileName, ULONG * pulAtt
extern HB_EXPORT BOOL hb_fsSetAttr ( BYTE * pszFileName, ULONG ulAttr );
extern HB_EXPORT void hb_fsSetError ( USHORT uiError ); /* set the file system DOS error number */
extern HB_EXPORT void hb_fsSetIOError ( BOOL fResult, USHORT uiOperation ); /* set the file system error number after IO operation */
extern HB_EXPORT BOOL hb_fsTruncAt ( HB_FHANDLE hFileHandle, HB_FOFFSET llOffset ); /* truncate file to given size */
extern HB_EXPORT USHORT hb_fsWrite ( HB_FHANDLE hFileHandle, const BYTE * pBuff, USHORT ulCount ); /* write to an open file from a buffer (<=64K) */
extern HB_EXPORT ULONG hb_fsWriteLarge ( HB_FHANDLE hFileHandle, const BYTE * pBuff, ULONG ulCount ); /* write to an open file from a buffer (>64K) */
extern HB_EXPORT ULONG hb_fsWriteAt ( HB_FHANDLE hFileHandle, const BYTE * pBuff, ULONG ulCount, HB_FOFFSET llOffset ); /* write to an open file at given offset from a buffer (>64K) */
extern HB_EXPORT HB_FHANDLE hb_fsPOpen ( BYTE * pFilename, BYTE * pMode );
extern HB_EXPORT HB_FHANDLE hb_fsGetOsHandle( HB_FHANDLE hFileHandle );
extern HB_EXPORT USHORT hb_fsGetFError ( void ); /* get FERROR() flag */
@@ -290,14 +295,34 @@ extern char * hb_fsAttrDecode( ULONG ulAttr, char * szAttr );
extern HB_EXPORT BYTE * hb_fsNameConv( BYTE * szFileName, BOOL * pfFree );
extern HB_EXPORT BOOL hb_fsMaxFilesError( void );
/* Harbour file functions with shared file handles and locks
* (buffers in the future)
*/
#ifndef _HB_FILE_INTERNAL_
typedef void * PHB_FILE;
#endif
HB_EXPORT PHB_FILE hb_fileExtOpen( BYTE * pFilename, BYTE * pDefExt,
USHORT uiExFlags, BYTE * pPaths,
PHB_ITEM pError );
HB_EXPORT PHB_FILE hb_fileCreateTemp( const BYTE * pszDir, const BYTE * pszPrefix,
ULONG ulAttr, BYTE * pszName );
HB_EXPORT void hb_fileClose( PHB_FILE pFile );
HB_EXPORT BOOL hb_fileLock( PHB_FILE pFile, HB_FOFFSET ulStart, HB_FOFFSET ulLen, int iType );
HB_EXPORT ULONG hb_fileReadAt( PHB_FILE pFile, BYTE * buffer, ULONG ulSize, HB_FOFFSET llOffset );
HB_EXPORT ULONG hb_fileWriteAt( PHB_FILE pFile, const BYTE * buffer, ULONG ulSize, HB_FOFFSET llOffset );
HB_EXPORT BOOL hb_fileTruncAt( PHB_FILE pFile, HB_FOFFSET llOffset );
HB_EXPORT HB_FOFFSET hb_fileSize( PHB_FILE pFile );
HB_EXPORT void hb_fileCommit( PHB_FILE pFile );
HB_EXPORT HB_FHANDLE hb_fileHandle( PHB_FILE pFile );
/* wrapper to fopen() which calls hb_fsNameConv() */
extern FILE * hb_fopen( const char *path, const char *mode );
#ifdef HB_LEGACY_LEVEL
/* Compatibility. Obsolete. */
extern HB_EXPORT BYTE * hb_fileNameConv( char * str );
#endif
/* wrapper to fopen() which calls hb_fsNameConv() */
extern FILE * hb_fopen( const char *path, const char *mode );
HB_EXTERN_END
#endif /* HB_APIFS_H_ */

View File

@@ -370,7 +370,7 @@ typedef struct _CDXINDEX
{
char * szFileName; /* Name of index file */
char * szRealName; /* Real name of index file */
HB_FHANDLE hFile; /* Index file handle */
PHB_FILE pFile; /* Index file handle */
struct _CDXAREA * pArea; /* Parent WorkArea */
struct _CDXINDEX * pNext; /* The next index in the list */
LPCDXTAG pCompound; /* Compound tag */
@@ -478,9 +478,9 @@ typedef struct _CDXAREA
* example.
*/
HB_FHANDLE hDataFile; /* Data file handle */
HB_FHANDLE hMemoFile; /* Memo file handle */
HB_FHANDLE hMemoTmpFile; /* Memo temporary file handle */
PHB_FILE pDataFile; /* Data file handle */
PHB_FILE pMemoFile; /* Memo file handle */
PHB_FILE pMemoTmpFile; /* Memo temporary file handle */
char * szDataFileName; /* Name of data file */
char * szMemoFileName; /* Name of memo file */
USHORT uiHeaderLen; /* Size of header */

View File

@@ -191,9 +191,9 @@ typedef struct _DBFAREA
* example.
*/
HB_FHANDLE hDataFile; /* Data file handle */
HB_FHANDLE hMemoFile; /* Memo file handle */
HB_FHANDLE hMemoTmpFile; /* Memo temporary file handle */
PHB_FILE pDataFile; /* Data file handle */
PHB_FILE pMemoFile; /* Memo file handle */
PHB_FILE pMemoTmpFile; /* Memo temporary file handle */
char * szDataFileName; /* Name of data file */
char * szMemoFileName; /* Name of memo file */
USHORT uiHeaderLen; /* Size of header */
@@ -368,7 +368,7 @@ extern HB_EXPORT ERRCODE hb_dbfSetMemoData( DBFAREAP pArea, USHORT uiIndex,
ULONG ulBlock, ULONG ulSize,
ULONG ulType );
extern HB_EXPORT ERRCODE hb_dbfGetEGcode( ERRCODE errCode );
extern HB_EXPORT BOOL hb_dbfLockIdxFile( HB_FHANDLE hFile, BYTE bScheme, USHORT usMode, HB_FOFFSET *pPoolPos );
extern HB_EXPORT BOOL hb_dbfLockIdxFile( PHB_FILE pFile, BYTE bScheme, USHORT usMode, HB_FOFFSET *pPoolPos );
extern HB_EXPORT BOOL hb_dbfLockIdxGetData( BYTE bScheme, HB_FOFFSET *ulPos, HB_FOFFSET *ulPool );
#ifndef HB_CDP_SUPPORT_OFF

View File

@@ -102,7 +102,7 @@ typedef struct _DELIMAREA
* example.
*/
HB_FHANDLE hFile; /* Data file handle */
PHB_FILE pFile; /* Data file handle */
char * szFileName; /* Name of data file */
char * szEol; /* EOL marker */
USHORT uiEolLen; /* Size of EOL marker */

View File

@@ -257,7 +257,7 @@ typedef struct _NTXINDEX
ULONG NextAvail;
ULONG TagBlock; /* Index attr, next free page */
struct _NTXAREA * Owner;
HB_FHANDLE DiskFile;
PHB_FILE DiskFile;
BOOL fDelete; /* delete on close flag */
BOOL fReadonly;
BOOL fShared;
@@ -372,9 +372,9 @@ typedef struct _NTXAREA
* example.
*/
HB_FHANDLE hDataFile; /* Data file handle */
HB_FHANDLE hMemoFile; /* Memo file handle */
HB_FHANDLE hMemoTmpFile; /* Memo temporary file handle */
PHB_FILE pDataFile; /* Data file handle */
PHB_FILE pMemoFile; /* Memo file handle */
PHB_FILE pMemoTmpFile; /* Memo temporary file handle */
char * szDataFileName; /* Name of data file */
char * szMemoFileName; /* Name of memo file */
USHORT uiHeaderLen; /* Size of header */

View File

@@ -102,7 +102,7 @@ typedef struct _SDFAREA
* example.
*/
HB_FHANDLE hFile; /* Data file handle */
PHB_FILE pFile; /* Data file handle */
char * szFileName; /* Name of data file */
char * szEol; /* EOL marker */
USHORT uiEolLen; /* Size of EOL marker */

View File

@@ -197,9 +197,6 @@ typedef struct
# endif
# else
extern HB_TLS_KEY hb_stack_key;
# define hb_stack_ptr ( ( PHB_STACK ) hb_tls_get( hb_stack_key ) )
# endif
# if defined( HB_STACK_PRELOAD ) && !defined( HB_USE_TLS )
# if defined( __BORLANDC__ )
static __inline void* hb_stack_ptr_from_tls( void )
{
@@ -212,9 +209,8 @@ typedef struct
/* ret (if function is not inlined) */
return (void*) _EAX;
}
# define HB_STACK_TLS_PRELOAD PHB_STACK _hb_stack_ptr_ = hb_stack_ptr_from_tls();
# elif defined( __MINGW32__ )
static __inline__ void * hb_stack_ptr_from_tls( void )
static __inline__ __attribute__ ((pure, malloc)) void * hb_stack_ptr_from_tls( void )
{
void * p;
__asm__ (
@@ -225,9 +221,15 @@ typedef struct
);
return p;
}
# define HB_STACK_TLS_PRELOAD PHB_STACK _hb_stack_ptr_ = hb_stack_ptr_from_tls();
# define hb_stack_ptr ( ( PHB_STACK ) hb_stack_ptr_from_tls() )
# endif
# if defined( HB_STACK_TLS_PRELOAD )
# if !defined( hb_stack_ptr )
# define hb_stack_ptr ( ( PHB_STACK ) hb_tls_get( hb_stack_key ) )
# endif
# endif
# if defined( HB_STACK_PRELOAD ) && !defined( HB_USE_TLS )
# if defined( __BORLANDC__ ) || defined( __MINGW32__ )
# define HB_STACK_TLS_PRELOAD PHB_STACK _hb_stack_ptr_ = ( PHB_STACK ) hb_stack_ptr_from_tls();
# undef hb_stack_ptr
# else
# define HB_STACK_TLS_PRELOAD PHB_STACK _hb_stack_ptr_ = hb_stack_ptr;

View File

@@ -200,16 +200,14 @@ static HB_LONG hb_dbfGetRowVer( DBFAREAP pArea, USHORT uiField, HB_LONG * pValue
fLck = TRUE;
}
hb_fsSeek( pArea->hDataFile, sizeof( DBFHEADER ) +
uiField * sizeof( DBFFIELD ), FS_SET );
if( hb_fsRead( pArea->hDataFile, ( BYTE * ) &dbField,
sizeof( dbField ) ) == sizeof( dbField ) )
if( hb_fileReadAt( pArea->pDataFile, ( BYTE * ) &dbField, sizeof( dbField ),
sizeof( DBFHEADER ) + uiField * sizeof( DBFFIELD ) ) ==
sizeof( dbField ) )
{
*pValue = HB_GET_LE_UINT64( &dbField.bReserved2 ) + 1;
HB_PUT_LE_UINT64( dbField.bReserved2, *pValue );
hb_fsSeek( pArea->hDataFile, sizeof( DBFHEADER ) +
uiField * sizeof( DBFFIELD ), FS_SET );
hb_fsWrite( pArea->hDataFile, ( BYTE * ) &dbField, sizeof( dbField ) );
hb_fileWriteAt( pArea->pDataFile, ( BYTE * ) &dbField, sizeof( dbField ),
sizeof( DBFHEADER ) + uiField * sizeof( DBFFIELD ) );
}
if( fLck )
@@ -226,16 +224,14 @@ static HB_LONG hb_dbfGetNextValue( DBFAREAP pArea, USHORT uiField )
HB_LONG nValue = 0;
DBFFIELD dbField;
hb_fsSeek( pArea->hDataFile, sizeof( DBFHEADER ) +
uiField * sizeof( DBFFIELD ), FS_SET );
if( hb_fsRead( pArea->hDataFile, ( BYTE * ) &dbField,
sizeof( dbField ) ) == sizeof( dbField ) )
if( hb_fileReadAt( pArea->pDataFile, ( BYTE * ) &dbField, sizeof( dbField ),
sizeof( DBFHEADER ) + uiField * sizeof( DBFFIELD ) ) ==
sizeof( dbField ) )
{
nValue = HB_GET_LE_UINT32( dbField.bCounter );
HB_PUT_LE_UINT32( dbField.bCounter, nValue + dbField.bStep );
hb_fsSeek( pArea->hDataFile, sizeof( DBFHEADER ) +
uiField * sizeof( DBFFIELD ), FS_SET );
hb_fsWrite( pArea->hDataFile, ( BYTE * ) &dbField, sizeof( dbField ) );
hb_fileWriteAt( pArea->pDataFile, ( BYTE * ) &dbField, sizeof( dbField ),
sizeof( DBFHEADER ) + uiField * sizeof( DBFFIELD ) );
}
return nValue;
@@ -483,10 +479,10 @@ static ULONG hb_dbfCalcRecCount( DBFAREAP pArea )
{
HB_TRACE(HB_TR_DEBUG, ("hb_dbfCalcRecCount(%p)", pArea));
if( pArea->hDataFile == FS_ERROR )
if( ! pArea->pDataFile )
return 0;
else
return ( ULONG ) ( ( hb_fsSeekLarge( pArea->hDataFile, 0, FS_END ) -
return ( ULONG ) ( ( hb_fileSize( pArea->pDataFile ) -
pArea->uiHeaderLen ) / pArea->uiRecordLen );
}
@@ -517,11 +513,11 @@ static BOOL hb_dbfReadRecord( DBFAREAP pArea )
}
/* Read data from file */
hb_fsSeekLarge( pArea->hDataFile, ( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( pArea->ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen, FS_SET );
if( hb_fsRead( pArea->hDataFile, pArea->pRecord, pArea->uiRecordLen ) !=
pArea->uiRecordLen )
if( hb_fileReadAt( pArea->pDataFile, pArea->pRecord, pArea->uiRecordLen,
( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( pArea->ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen ) !=
( ULONG ) pArea->uiRecordLen )
{
PHB_ITEM pError = hb_errNew();
@@ -1228,17 +1224,17 @@ HB_EXPORT BOOL hb_dbfLockIdxGetData( BYTE bScheme, HB_FOFFSET *ulPos, HB_FOFFSET
* This function is common for different MEMO implementation
* so I left it in DBF.
*/
HB_EXPORT BOOL hb_dbfLockIdxFile( HB_FHANDLE hFile, BYTE bScheme, USHORT usMode, HB_FOFFSET *pPoolPos )
HB_EXPORT BOOL hb_dbfLockIdxFile( PHB_FILE pFile, BYTE bScheme, USHORT usMode, HB_FOFFSET *pPoolPos )
{
HB_FOFFSET ulPos, ulPool, ulSize = 1;
BOOL fRet = FALSE, fWait;
BOOL fRet = FALSE;
if( !hb_dbfLockIdxGetData( bScheme, &ulPos, &ulPool ) )
{
return fRet;
}
do
for( ;; )
{
switch( usMode & FL_MASK )
{
@@ -1274,11 +1270,12 @@ HB_EXPORT BOOL hb_dbfLockIdxFile( HB_FHANDLE hFile, BYTE bScheme, USHORT usMode,
default:
return FALSE;
}
fRet = hb_fsLockLarge( hFile, ulPos + *pPoolPos, ulSize, usMode );
fWait = ( !fRet && ( usMode & FLX_WAIT ) != 0 && ( usMode & FL_MASK ) == FL_LOCK );
fRet = hb_fileLock( pFile, ulPos + *pPoolPos, ulSize, usMode );
if( fRet || ( usMode & FLX_WAIT ) == 0 || ( usMode & FL_MASK ) != FL_LOCK )
break;
/* TODO: call special error handler (LOCKHANDLER) here if fWait */
} while( fWait );
hb_releaseCPU();
}
return fRet;
}
@@ -1785,12 +1782,12 @@ static ERRCODE hb_dbfFlush( DBFAREAP pArea )
{
if( pArea->fDataFlush )
{
hb_fsCommit( pArea->hDataFile );
hb_fileCommit( pArea->pDataFile );
pArea->fDataFlush = FALSE;
}
if( pArea->fHasMemo && pArea->hMemoFile != FS_ERROR && pArea->fMemoFlush )
if( pArea->fHasMemo && pArea->pMemoFile && pArea->fMemoFlush )
{
hb_fsCommit( pArea->hMemoFile );
hb_fileCommit( pArea->pMemoFile );
pArea->fMemoFlush = FALSE;
}
}
@@ -2107,7 +2104,7 @@ static ERRCODE hb_dbfGoCold( DBFAREAP pArea )
if( pArea->fModStamp )
hb_dbfUpdateStampFields( pArea );
/* Write current record */
if( ! hb_dbfWriteRecord( pArea ) )
return FAILURE;
@@ -2218,11 +2215,10 @@ static ERRCODE hb_dbfPutRec( DBFAREAP pArea, BYTE * pBuffer )
}
/* Write data to file */
hb_fsSeekLarge( pArea->hDataFile, ( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( pArea->ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen, FS_SET );
uiWritten = hb_fsWrite( pArea->hDataFile, pRecord, pArea->uiRecordLen );
uiWritten = hb_fileWriteAt( pArea->pDataFile, pRecord, pArea->uiRecordLen,
( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( pArea->ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen );
if( pRecord != pArea->pRecord )
hb_xfree( pRecord );
@@ -2639,7 +2635,7 @@ static ERRCODE hb_dbfClose( DBFAREAP pArea )
pArea->lpdbPendingRel = NULL;
/* Update record and unlock records */
if( pArea->hDataFile != FS_ERROR )
if( pArea->pDataFile )
{
/* update buffers */
SELF_GOCOLD( ( AREAP ) pArea );
@@ -2659,17 +2655,17 @@ static ERRCODE hb_dbfClose( DBFAREAP pArea )
SUPER_CLOSE( ( AREAP ) pArea );
if( pArea->hDataFile != FS_ERROR )
if( pArea->pDataFile )
{
hb_fsClose( pArea->hDataFile );
pArea->hDataFile = FS_ERROR;
hb_fileClose( pArea->pDataFile );
pArea->pDataFile = NULL;
}
/* Close the memo file */
if( pArea->fHasMemo && pArea->hMemoFile != FS_ERROR )
if( pArea->fHasMemo && pArea->pMemoFile )
{
hb_fsClose( pArea->hMemoFile );
pArea->hMemoFile = FS_ERROR;
hb_fileClose( pArea->pMemoFile );
pArea->pMemoFile = NULL;
}
/* Free field offset array */
@@ -2721,9 +2717,11 @@ static ERRCODE hb_dbfClose( DBFAREAP pArea )
static ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo )
{
ERRCODE errCode = SUCCESS;
USHORT uiSize, uiCount;
ULONG ulSize;
USHORT uiCount;
BOOL fRetry, fError, fRawBlob;
DBFFIELD * pBuffer, *pThisField;
DBFFIELD * pThisField;
BYTE * pBuffer;
PHB_FNAME pFileName;
PHB_ITEM pItem = NULL, pError;
BYTE szFileName[ _POSIX_PATH_MAX + 1 ];
@@ -2827,11 +2825,11 @@ static ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo )
/* Try create */
do
{
pArea->hDataFile = hb_fsExtOpen( szFileName, NULL,
FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( pArea->hDataFile == FS_ERROR )
pArea->pDataFile = hb_fileExtOpen( szFileName, NULL,
FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( ! pArea->pDataFile )
{
if( !pError )
{
@@ -2854,7 +2852,7 @@ static ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo )
hb_itemRelease( pError );
}
if( pArea->hDataFile == FS_ERROR )
if( ! pArea->pDataFile )
{
pArea->lpdbOpenInfo = NULL;
return FAILURE;
@@ -2863,17 +2861,18 @@ static ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo )
pArea->szDataFileName = hb_strdup( ( char * ) szFileName );
uiSize = pArea->uiFieldCount * sizeof( DBFFIELD );
ulSize = pArea->uiFieldCount * sizeof( DBFFIELD ) +
( pArea->bTableType == DB_DBF_VFP ? 1 : 2 );
if( pArea->uiFieldCount )
{
pBuffer = ( DBFFIELD * ) hb_xgrab( uiSize );
memset( pBuffer, 0, uiSize );
pBuffer = ( BYTE * ) hb_xgrab( ulSize + 1 );
memset( pBuffer, 0, ulSize );
}
else
{
pBuffer = NULL;
}
pThisField = pBuffer;
pThisField = ( DBFFIELD * ) pBuffer;
pArea->fHasMemo = fError = FALSE;
@@ -3078,8 +3077,7 @@ static ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo )
pArea->fShared = FALSE; /* pCreateInfo->fShared; */
pArea->fReadonly = FALSE; /* pCreateInfo->fReadonly */
pArea->ulRecCount = 0;
pArea->uiHeaderLen = sizeof( DBFHEADER ) + uiSize +
( pArea->bTableType == DB_DBF_VFP ? 1 : 2 );
pArea->uiHeaderLen = ( USHORT ) ( sizeof( DBFHEADER ) + ulSize );
if( fRawBlob )
{
pArea->fHasMemo = TRUE;
@@ -3128,30 +3126,33 @@ static ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo )
errCode = SELF_WRITEDBHEADER( ( AREAP ) pArea );
if( errCode != SUCCESS )
{
if( pBuffer )
hb_xfree( pBuffer );
hb_xfree( pBuffer );
SELF_CLOSE( ( AREAP ) pArea );
pArea->lpdbOpenInfo = NULL;
return errCode;
}
/* Write fields and eof mark */
if( hb_fsWrite( pArea->hDataFile, ( BYTE * ) pBuffer, uiSize ) != uiSize ||
( pArea->bTableType == DB_DBF_VFP ?
hb_fsWrite( pArea->hDataFile, ( BYTE * ) "\r\032", 2 ) != 2 :
hb_fsWrite( pArea->hDataFile, ( BYTE * ) "\r\0\032", 3 ) != 3 ) )
if( pArea->bTableType == DB_DBF_VFP )
pBuffer[ ulSize - 1 ] = '\r';
else
{
pBuffer[ ulSize - 2 ] = '\r';
pBuffer[ ulSize - 1 ] = '\0';
}
pBuffer[ ulSize ] = ' ';
if( hb_fileWriteAt( pArea->pDataFile, pBuffer, ulSize + 1,
sizeof( DBFHEADER ) ) != ulSize + 1 )
{
/* TODO: add RT error */
if( pBuffer )
hb_xfree( pBuffer );
hb_xfree( pBuffer );
SELF_CLOSE( ( AREAP ) pArea );
pArea->lpdbOpenInfo = NULL;
return FAILURE;
}
pArea->fDataFlush = TRUE;
if( pBuffer )
hb_xfree( pBuffer );
hb_xfree( pBuffer );
}
/* Create memo file */
@@ -3236,7 +3237,7 @@ static ERRCODE hb_dbfInfo( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
break;
case DBI_TABLETYPE:
if( pArea->hDataFile == FS_ERROR )
if( !pArea->pDataFile )
{
hb_itemClear( pItem );
return SELF_RDDINFO( SELF_RDDNODE( pArea ), RDDI_TABLETYPE, 0, pItem );
@@ -3245,11 +3246,11 @@ static ERRCODE hb_dbfInfo( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
break;
case DBI_FILEHANDLE:
hb_itemPutNL( pItem, ( LONG ) pArea->hDataFile );
hb_itemPutNInt( pItem, ( HB_NHANDLE ) hb_fileHandle( pArea->pDataFile ) );
break;
case DBI_MEMOHANDLE:
hb_itemPutNL( pItem, ( LONG ) pArea->hMemoFile );
hb_itemPutNInt( pItem, ( HB_NHANDLE ) hb_fileHandle( pArea->pMemoFile ) );
break;
case DBI_SHARED:
@@ -3552,7 +3553,7 @@ static ERRCODE hb_dbfNewArea( DBFAREAP pArea )
if( SUPER_NEW( ( AREAP ) pArea ) == FAILURE )
return FAILURE;
pArea->hDataFile = pArea->hMemoFile = pArea->hMemoTmpFile = FS_ERROR;
pArea->pDataFile = pArea->pMemoFile = pArea->pMemoTmpFile = NULL;
pArea->fDataFlush = pArea->fMemoFlush = FALSE;
/* Index dirty read flag initialized to global RDD setting */
pArea->uiDirtyRead = HB_IDXREAD_DEFAULT;
@@ -3567,7 +3568,8 @@ static ERRCODE hb_dbfNewArea( DBFAREAP pArea )
static ERRCODE hb_dbfOpen( DBFAREAP pArea, LPDBOPENINFO pOpenInfo )
{
ERRCODE errCode;
USHORT uiFlags, uiFields, uiSize, uiCount, uiSkip;
USHORT uiFlags, uiFields, uiCount, uiSkip;
ULONG ulSize;
BOOL fRetry, fRawBlob;
PHB_ITEM pError, pItem;
PHB_FNAME pFileName;
@@ -3691,10 +3693,10 @@ static ERRCODE hb_dbfOpen( DBFAREAP pArea, LPDBOPENINFO pOpenInfo )
/* Try open */
do
{
pArea->hDataFile = hb_fsExtOpen( szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( pArea->hDataFile == FS_ERROR )
pArea->pDataFile = hb_fileExtOpen( szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( !pArea->pDataFile )
{
if( !pError )
{
@@ -3719,7 +3721,7 @@ static ERRCODE hb_dbfOpen( DBFAREAP pArea, LPDBOPENINFO pOpenInfo )
}
/* Exit if error */
if( pArea->hDataFile == FS_ERROR )
if( !pArea->pDataFile )
{
SELF_CLOSE( ( AREAP ) pArea );
pArea->lpdbOpenInfo = NULL;
@@ -3741,14 +3743,14 @@ static ERRCODE hb_dbfOpen( DBFAREAP pArea, LPDBOPENINFO pOpenInfo )
/* Add fields */
uiSkip = 0;
uiFields = ( pArea->uiHeaderLen - sizeof( DBFHEADER ) ) / sizeof( DBFFIELD );
uiSize = uiFields * sizeof( DBFFIELD );
pBuffer = uiFields ? ( BYTE * ) hb_xgrab( uiSize ) : NULL;
ulSize = ( ULONG ) uiFields * sizeof( DBFFIELD );
pBuffer = uiFields ? ( BYTE * ) hb_xgrab( ulSize ) : NULL;
/* Read fields and exit if error */
do
{
hb_fsSeek( pArea->hDataFile, sizeof( DBFHEADER ), FS_SET );
if( hb_fsRead( pArea->hDataFile, pBuffer, uiSize ) != uiSize )
if( hb_fileReadAt( pArea->pDataFile, pBuffer, ulSize,
sizeof( DBFHEADER ) ) != ulSize )
{
errCode = FAILURE;
if( !pError )
@@ -4591,9 +4593,9 @@ static ERRCODE hb_dbfRawLock( DBFAREAP pArea, USHORT uiAction, ULONG ulRecNo )
if( !pArea->fFLocked )
{
if( iDir < 0 )
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos - ulFlSize, ulFlSize, FL_LOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos - ulFlSize, ulFlSize, FL_LOCK );
else
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos + 1, ulFlSize, FL_LOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos + 1, ulFlSize, FL_LOCK );
if( !fLck )
uiErr = FAILURE;
@@ -4606,9 +4608,9 @@ static ERRCODE hb_dbfRawLock( DBFAREAP pArea, USHORT uiAction, ULONG ulRecNo )
if( pArea->fFLocked )
{
if( iDir < 0 )
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos - ulFlSize, ulFlSize, FL_UNLOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos - ulFlSize, ulFlSize, FL_UNLOCK );
else
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos + 1, ulFlSize, FL_UNLOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos + 1, ulFlSize, FL_UNLOCK );
if( !fLck )
uiErr = FAILURE;
@@ -4620,11 +4622,11 @@ static ERRCODE hb_dbfRawLock( DBFAREAP pArea, USHORT uiAction, ULONG ulRecNo )
if( !pArea->fFLocked )
{
if( iDir < 0 )
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos - ulRecNo, ulRlSize, FL_LOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos - ulRecNo, ulRlSize, FL_LOCK );
else if( iDir == 2 )
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos + ( ulRecNo - 1 ) * pArea->uiRecordLen + pArea->uiHeaderLen, ulRlSize, FL_LOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos + ( ulRecNo - 1 ) * pArea->uiRecordLen + pArea->uiHeaderLen, ulRlSize, FL_LOCK );
else
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos + ulRecNo, ulRlSize, FL_LOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos + ulRecNo, ulRlSize, FL_LOCK );
if( !fLck )
uiErr = FAILURE;
@@ -4635,11 +4637,11 @@ static ERRCODE hb_dbfRawLock( DBFAREAP pArea, USHORT uiAction, ULONG ulRecNo )
if( !pArea->fFLocked )
{
if( iDir < 0 )
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos - ulRecNo, ulRlSize, FL_UNLOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos - ulRecNo, ulRlSize, FL_UNLOCK );
else if( iDir == 2 )
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos + ( ulRecNo - 1 ) * pArea->uiRecordLen + pArea->uiHeaderLen, ulRlSize, FL_UNLOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos + ( ulRecNo - 1 ) * pArea->uiRecordLen + pArea->uiHeaderLen, ulRlSize, FL_UNLOCK );
else
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos + ulRecNo, ulRlSize, FL_UNLOCK );
fLck = hb_fileLock( pArea->pDataFile, ulPos + ulRecNo, ulRlSize, FL_UNLOCK );
if( !fLck )
uiErr = FAILURE;
}
@@ -4649,11 +4651,14 @@ static ERRCODE hb_dbfRawLock( DBFAREAP pArea, USHORT uiAction, ULONG ulRecNo )
case HEADER_LOCK:
if( !pArea->fHeaderLocked )
{
do
for( ;; )
{
fLck = hb_fsLockLarge( pArea->hDataFile, ulPos, 1, FL_LOCK | FLX_WAIT );
fLck = hb_fileLock( pArea->pDataFile, ulPos, 1, FL_LOCK | FLX_WAIT );
/* TODO: call special error handler (LOCKHANDLER) hiere if !fLck */
} while( !fLck );
if( fLck )
break;
hb_releaseCPU();
}
if( !fLck )
uiErr = FAILURE;
else
@@ -4665,7 +4670,7 @@ static ERRCODE hb_dbfRawLock( DBFAREAP pArea, USHORT uiAction, ULONG ulRecNo )
case HEADER_UNLOCK:
if( pArea->fHeaderLocked )
{
if( !hb_fsLockLarge( pArea->hDataFile, ulPos, 1, FL_UNLOCK ) )
if( !hb_fileLock( pArea->pDataFile, ulPos, 1, FL_UNLOCK ) )
uiErr = FAILURE;
pArea->fHeaderLocked = FALSE;
}
@@ -4786,25 +4791,25 @@ static ERRCODE hb_dbfGetValueFile( DBFAREAP pArea, USHORT uiIndex, BYTE * szFile
pField = pArea->lpFields + uiIndex;
if( pField->uiType == HB_FT_STRING )
{
HB_FHANDLE hFile;
PHB_FILE pFile;
hFile = hb_fsExtOpen( szFile, NULL, FO_WRITE | FO_EXCLUSIVE |
FXO_DEFAULTS | FXO_SHARELOCK |
( uiMode == FILEGET_APPEND ? FXO_APPEND : FXO_TRUNCATE ),
NULL, NULL );
if( hFile == FS_ERROR )
pFile = hb_fileExtOpen( szFile, NULL, FO_WRITE | FO_EXCLUSIVE |
FXO_DEFAULTS | FXO_SHARELOCK |
( uiMode == FILEGET_APPEND ? FXO_APPEND : FXO_TRUNCATE ),
NULL, NULL );
if( !pFile )
{
uiError = uiMode != FILEGET_APPEND ? EDBF_CREATE : EDBF_OPEN_DBF;
}
else
{
hb_fsSeekLarge( hFile, 0, FS_END );
if( hb_fsWrite( hFile, pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
pField->uiLen ) != pField->uiLen )
if( hb_fileWriteAt( pFile, pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
pField->uiLen, hb_fileSize( pFile ) ) !=
( ULONG ) pField->uiLen )
{
uiError = EDBF_WRITE;
}
hb_fsClose( hFile );
hb_fileClose( pFile );
}
}
else
@@ -4886,22 +4891,22 @@ static ERRCODE hb_dbfPutValueFile( DBFAREAP pArea, USHORT uiIndex, BYTE * szFile
pField = pArea->lpFields + uiIndex;
if( pField->uiType == HB_FT_STRING )
{
HB_FHANDLE hFile;
PHB_FILE pFile;
hFile = hb_fsExtOpen( szFile, NULL, FO_READ | FO_DENYNONE |
FXO_DEFAULTS | FXO_SHARELOCK, NULL, NULL );
if( hFile == FS_ERROR )
pFile = hb_fileExtOpen( szFile, NULL, FO_READ | FO_DENYNONE |
FXO_DEFAULTS | FXO_SHARELOCK, NULL, NULL );
if( !pFile )
{
uiError = EDBF_OPEN_DBF;
}
else
{
uiRead = hb_fsRead( hFile, pArea->pRecord +
pArea->pFieldOffset[ uiIndex ], pField->uiLen );
uiRead = hb_fileReadAt( pFile, pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
pField->uiLen, 0 );
if( uiRead != ( USHORT ) FS_ERROR && uiRead < pField->uiLen )
memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ] + uiRead,
' ', pField->uiLen - uiRead );
hb_fsClose( hFile );
hb_fileClose( pFile );
}
}
else
@@ -4945,9 +4950,8 @@ static ERRCODE hb_dbfReadDBHeader( DBFAREAP pArea )
{
fError = FALSE;
hb_fsSeek( pArea->hDataFile, 0, FS_SET );
if( hb_fsRead( pArea->hDataFile, ( BYTE * ) &pArea->dbfHeader,
sizeof( DBFHEADER ) ) != sizeof( DBFHEADER ) )
if( hb_fileReadAt( pArea->pDataFile, ( BYTE * ) &pArea->dbfHeader,
sizeof( DBFHEADER ), 0 ) != sizeof( DBFHEADER ) )
{
fError = TRUE;
}
@@ -5118,20 +5122,19 @@ static ERRCODE hb_dbfWriteDBHeader( DBFAREAP pArea )
else
{
/* Exclusive mode */
/* Seek to logical eof and write eof mark */
hb_fsSeekLarge( pArea->hDataFile, ( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) pArea->uiRecordLen *
( HB_FOFFSET ) pArea->ulRecCount, FS_SET );
hb_fsWrite( pArea->hDataFile, ( BYTE * ) "\032", 1 );
hb_fsWrite( pArea->hDataFile, NULL, 0 );
/* write eof mark */
HB_FOFFSET llOffset = ( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) pArea->uiRecordLen *
( HB_FOFFSET ) pArea->ulRecCount;
hb_fileWriteAt( pArea->pDataFile, ( BYTE * ) "\032", 1, llOffset );
hb_fileTruncAt( pArea->pDataFile, llOffset + 1 );
}
HB_PUT_LE_UINT32( pArea->dbfHeader.ulRecCount, pArea->ulRecCount );
HB_PUT_LE_UINT16( pArea->dbfHeader.uiHeaderLen, pArea->uiHeaderLen );
HB_PUT_LE_UINT16( pArea->dbfHeader.uiRecordLen, pArea->uiRecordLen );
hb_fsSeek( pArea->hDataFile, 0, FS_SET );
if( hb_fsWrite( pArea->hDataFile, ( BYTE * ) &pArea->dbfHeader,
sizeof( DBFHEADER ) ) == sizeof( DBFHEADER ) )
if( hb_fileWriteAt( pArea->pDataFile, ( BYTE * ) &pArea->dbfHeader,
sizeof( DBFHEADER ), 0 ) == sizeof( DBFHEADER ) )
{
errCode = SUCCESS;
}

View File

@@ -1055,7 +1055,7 @@ static void hb_cdxIndexCheckBuffers( LPCDXINDEX pIndex )
*/
static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader )
{
HB_FHANDLE hFile = pIndex->hFile;
PHB_FILE pFile = pIndex->pFile;
BYTE byBuf[4];
ULONG ulPos;
@@ -1080,8 +1080,7 @@ static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader )
}
else
{
if ( hb_fsSeekLarge( hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos ||
hb_fsRead( hFile, (BYTE *) byBuf, 4 ) != 4 )
if ( hb_fileReadAt( pFile, (BYTE *) byBuf, 4, ulPos ) != 4 )
hb_errInternal( EDBF_READ, "hb_cdxIndexGetAvailPage: Read index page failed.", NULL, NULL );
pIndex->freePage = HB_GET_LE_UINT32( byBuf );
#ifdef HB_CDX_DBGUPDT
@@ -1096,21 +1095,22 @@ static ULONG hb_cdxIndexGetAvailPage( LPCDXINDEX pIndex, BOOL bHeader )
if ( pIndex->nextAvail != CDX_DUMMYNODE )
ulPos = pIndex->nextAvail;
else
ulPos = ( ULONG ) hb_fsSeekLarge( hFile, 0, FS_END );
ulPos = ( ULONG ) hb_fileSize( pFile );
pIndex->nextAvail = ulPos + iCnt * CDX_PAGELEN;
/* TODO: ### */
if ( bHeader )
{
BYTE byBuf[CDX_PAGELEN];
HB_FOFFSET fOffset = ulPos;
memset( byBuf, 0, CDX_PAGELEN );
if ( hb_fsSeekLarge( hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos )
hb_errInternal( EDBF_WRITE, "Write in index page failed.(1)", NULL, NULL );
while ( iCnt-- )
do
{
if ( hb_fsWrite( hFile, byBuf, CDX_PAGELEN ) != CDX_PAGELEN )
hb_errInternal( EDBF_WRITE, "Write in index page failed.(2)", NULL, NULL );
if( hb_fileWriteAt( pFile, byBuf, CDX_PAGELEN, fOffset ) != CDX_PAGELEN )
hb_errInternal( EDBF_WRITE, "Write in index page failed.", NULL, NULL );
fOffset += CDX_PAGELEN;
}
while( --iCnt );
pIndex->fChanged = TRUE;
}
}
@@ -1169,8 +1169,7 @@ static void hb_cdxIndexFlushAvailPage( LPCDXINDEX pIndex )
fClean = FALSE;
}
HB_PUT_LE_UINT32( byPageBuf, pLst->ulAddr );
if ( hb_fsSeekLarge( pIndex->hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos ||
hb_fsWrite( pIndex->hFile, byPageBuf, CDX_PAGELEN ) != CDX_PAGELEN )
if( hb_fileWriteAt( pIndex->pFile, byPageBuf, CDX_PAGELEN, ulPos ) != CDX_PAGELEN )
{
hb_errInternal( EDBF_WRITE, "Write in index page failed.", NULL, NULL );
}
@@ -1205,13 +1204,12 @@ static void hb_cdxIndexDropAvailPage( LPCDXINDEX pIndex )
static void hb_cdxIndexPageWrite( LPCDXINDEX pIndex, ULONG ulPos, BYTE * pBuffer,
USHORT uiSize )
{
if ( pIndex->fReadonly )
if( pIndex->fReadonly )
hb_errInternal( 9101, "hb_cdxIndexPageWrite on readonly database.", NULL, NULL );
if ( pIndex->fShared && !pIndex->lockWrite )
if( pIndex->fShared && !pIndex->lockWrite )
hb_errInternal( 9102, "hb_cdxIndexPageWrite on not locked index file.", NULL, NULL );
if ( hb_fsSeekLarge( pIndex->hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos ||
hb_fsWrite( pIndex->hFile, pBuffer, uiSize ) != uiSize )
if( hb_fileWriteAt( pIndex->pFile, pBuffer, uiSize, ulPos ) != ( ULONG ) uiSize )
hb_errInternal( EDBF_WRITE, "Write in index page failed.", NULL, NULL );
pIndex->fChanged = TRUE;
#ifdef HB_CDX_DBGUPDT
@@ -1225,11 +1223,10 @@ static void hb_cdxIndexPageWrite( LPCDXINDEX pIndex, ULONG ulPos, BYTE * pBuffer
static void hb_cdxIndexPageRead( LPCDXINDEX pIndex, ULONG ulPos, BYTE * pBuffer,
USHORT uiSize )
{
if ( pIndex->fShared && !( pIndex->lockRead || pIndex->lockWrite ) )
if( pIndex->fShared && !( pIndex->lockRead || pIndex->lockWrite ) )
hb_errInternal( 9103, "hb_cdxIndexPageRead on not locked index file.", NULL, NULL );
if ( hb_fsSeekLarge( pIndex->hFile, ulPos, FS_SET ) != ( HB_FOFFSET ) ulPos ||
hb_fsRead( pIndex->hFile, pBuffer, uiSize ) != uiSize )
if( hb_fileReadAt( pIndex->pFile, pBuffer, uiSize, ulPos ) != ( ULONG ) uiSize )
hb_errInternal( EDBF_READ, "hb_cdxIndexPageRead: Read index page failed.", NULL, NULL );
#ifdef HB_CDX_DBGUPDT
cdxReadNO++;
@@ -1244,10 +1241,9 @@ static void hb_cdxIndexCheckVersion( LPCDXINDEX pIndex )
BYTE byBuf[8];
ULONG ulVer, ulFree;
if ( hb_fsSeek( pIndex->hFile, 0x04, FS_SET ) != 0x04 ||
hb_fsRead( pIndex->hFile, byBuf, 8 ) != 8 )
if( hb_fileReadAt( pIndex->pFile, byBuf, 8, 0x04 ) != 8 )
{
if ( pIndex->lockWrite > 0 && hb_fsSeek( pIndex->hFile, 0, FS_END ) == 0 )
if( pIndex->lockWrite > 0 && hb_fileSize( pIndex->pFile ) == 0 )
memset( byBuf, 0, 8 );
else
hb_errInternal( 2155, "hb_cdxIndexCheckVersion: Read error on index heading page.", NULL, NULL );
@@ -1293,7 +1289,7 @@ static BOOL hb_cdxIndexLockRead( LPCDXINDEX pIndex )
pIndex->RdLck = TRUE;
#endif
ret = hb_dbfLockIdxFile( pIndex->hFile, pIndex->pArea->bLockType,
ret = hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType,
FL_LOCK | FLX_SHARED | FLX_WAIT, &pIndex->ulLockPos );
if ( !ret )
hb_cdxErrorRT( pIndex->pArea, EG_LOCK, EDBF_LOCK, pIndex->szFileName, hb_fsError(), 0 );
@@ -1334,7 +1330,7 @@ static BOOL hb_cdxIndexLockWrite( LPCDXINDEX pIndex )
hb_errInternal( 9107, "hb_cdxIndexLockWrite: lock failure (*)", NULL, NULL );
pIndex->WrLck = TRUE;
#endif
ret = hb_dbfLockIdxFile( pIndex->hFile, pIndex->pArea->bLockType,
ret = hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType,
FL_LOCK | FLX_EXCLUSIVE | FLX_WAIT, &pIndex->ulLockPos );
}
if ( !ret )
@@ -1377,7 +1373,7 @@ static BOOL hb_cdxIndexUnLockRead( LPCDXINDEX pIndex )
hb_errInternal( 9108, "hb_cdxIndexUnLockRead: unlock error (*)", NULL, NULL );
pIndex->RdLck = FALSE;
#endif
if ( !hb_dbfLockIdxFile( pIndex->hFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) )
if ( !hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) )
{
hb_errInternal( 9108, "hb_cdxIndexUnLockRead: unlock error.", NULL, NULL );
}
@@ -1417,8 +1413,7 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex )
(pIndex->ulVersion)++;
HB_PUT_LE_UINT32( &byBuf[0], pIndex->freePage );
HB_PUT_BE_UINT32( &byBuf[4], pIndex->ulVersion );
if ( hb_fsSeek( pIndex->hFile, 0x04, FS_SET ) != 0x04 ||
hb_fsWrite( pIndex->hFile, byBuf, 8) != 8 )
if( hb_fileWriteAt( pIndex->pFile, byBuf, 8, 0x04 ) != 8 )
{
hb_errInternal( EDBF_WRITE, "Write in index page failed (ver)", NULL, NULL );
}
@@ -1430,7 +1425,7 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex )
hb_errInternal( 9108, "hb_cdxIndexUnLockWrite: unlock error (*)", NULL, NULL );
pIndex->WrLck = FALSE;
#endif
if ( !hb_dbfLockIdxFile( pIndex->hFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) )
if ( !hb_dbfLockIdxFile( pIndex->pFile, pIndex->pArea->bLockType, FL_UNLOCK, &pIndex->ulLockPos ) )
{
hb_errInternal( 9108, "hb_cdxIndexUnLockWrite: unlock error.", NULL, NULL );
}
@@ -1441,8 +1436,7 @@ static BOOL hb_cdxIndexUnLockWrite( LPCDXINDEX pIndex )
{
BYTE byBuf[4];
HB_PUT_LE_UINT32( &byBuf[0], pIndex->freePage );
if ( hb_fsSeek( pIndex->hFile, 0x04, FS_SET ) != 0x04 ||
hb_fsWrite( pIndex->hFile, byBuf, 4) != 4 )
if( hb_fileWriteAt( pIndex->pFile, byBuf, 4, 0x04 ) != 4 )
{
hb_errInternal( EDBF_WRITE, "Write in index page failed (ver.ex)", NULL, NULL );
}
@@ -3498,7 +3492,7 @@ static void hb_cdxTagLoad( LPCDXTAG pTag )
* invalid key value length
*/
if( pTag->RootBlock == 0 || pTag->RootBlock % CDX_PAGELEN != 0 ||
( HB_FOFFSET ) pTag->RootBlock >= hb_fsSeekLarge( pTag->pIndex->hFile, 0, FS_END ) ||
( HB_FOFFSET ) pTag->RootBlock >= hb_fileSize( pTag->pIndex->pFile ) ||
HB_GET_LE_UINT16( tagHeader.keySize ) > CDX_MAXKEY ||
uiForPos + uiForLen > CDX_HEADEREXPLEN ||
uiKeyPos + uiKeyLen > CDX_HEADEREXPLEN ||
@@ -4712,8 +4706,7 @@ static void hb_cdxIndexReindex( LPCDXINDEX pIndex )
pIndex->ulVersion = 0;
pIndex->nextAvail = 0;
pIndex->freePage = 0;
hb_fsSeek( pIndex->hFile, 0, FS_SET );
hb_fsWrite( pIndex->hFile, NULL, 0 );
hb_fileTruncAt( pIndex->pFile, 0 );
pIndex->fChanged = TRUE;
/* Rebuild the compound (master) tag */
@@ -4746,7 +4739,7 @@ static LPCDXINDEX hb_cdxIndexNew( CDXAREAP pArea )
pIndex = ( LPCDXINDEX ) hb_xgrab( sizeof( CDXINDEX ) );
memset( pIndex, 0, sizeof( CDXINDEX ) );
pIndex->hFile = FS_ERROR;
pIndex->pFile = NULL;
pIndex->pArea = pArea;
pIndex->nextAvail = CDX_DUMMYNODE;
return pIndex;
@@ -4786,9 +4779,9 @@ static void hb_cdxIndexFree( LPCDXINDEX pIndex )
hb_cdxIndexFreeTags( pIndex );
/* Close file */
if( pIndex->hFile != FS_ERROR )
if( pIndex->pFile )
{
hb_fsClose( pIndex->hFile );
hb_fileClose( pIndex->pFile );
if( pIndex->fDelete )
{
hb_fsDelete( ( BYTE * ) ( pIndex->szRealName ?
@@ -6773,9 +6766,9 @@ static ERRCODE hb_cdxFlush( CDXAREAP pArea )
pIndex = pArea->lpIndexes;
while ( pIndex )
{
if ( pIndex->hFile != FS_ERROR && pIndex->fFlush )
if ( pIndex->pFile && pIndex->fFlush )
{
hb_fsCommit( pIndex->hFile );
hb_fileCommit( pIndex->pFile );
pIndex->fFlush = FALSE;
}
pIndex = pIndex->pNext;
@@ -7162,7 +7155,7 @@ static ERRCODE hb_cdxZap ( CDXAREAP pArea )
static ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo )
{
USHORT uiFlags;
HB_FHANDLE hFile;
PHB_FILE pFile;
char szBaseName[ CDX_MAXTAGNAMELEN + 1 ];
char szFileName[ _POSIX_PATH_MAX + 1 ];
LPCDXINDEX pIndex, * pIndexPtr;
@@ -7200,33 +7193,33 @@ static ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo )
( pArea->fShared ? FO_DENYNONE : FO_EXCLUSIVE );
do
{
hFile = hb_fsExtOpen( ( BYTE * ) szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
if( hFile == FS_ERROR )
pFile = hb_fileExtOpen( ( BYTE * ) szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
if( !pFile )
bRetry = ( hb_cdxErrorRT( pArea, EG_OPEN, EDBF_OPEN_INDEX, szFileName,
hb_fsError(), EF_CANRETRY | EF_CANDEFAULT ) == E_RETRY );
else
{
if( hb_fsSeekLarge( hFile, 0, FS_END ) <= ( HB_FOFFSET ) sizeof( CDXTAGHEADER ) )
if( hb_fileSize( pFile ) <= ( HB_FOFFSET ) sizeof( CDXTAGHEADER ) )
{
hb_fsClose( hFile );
hFile = FS_ERROR;
hb_fileClose( pFile );
pFile = NULL;
hb_cdxErrorRT( pArea, EG_CORRUPTION, EDBF_CORRUPT,
szFileName, hb_fsError(), EF_CANDEFAULT );
}
bRetry = FALSE;
}
} while ( bRetry );
} while( bRetry );
if ( hFile == FS_ERROR )
if( !pFile )
{
return FAILURE;
}
pIndex = hb_cdxIndexNew( pArea );
pIndex->hFile = hFile;
pIndex->pFile = pFile;
pIndex->fShared = pArea->fShared;
pIndex->fReadonly = pArea->fReadonly;
pIndex->szFileName = hb_strdup( szFileName );
@@ -7602,40 +7595,40 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo
if ( !fOpenedIndex )
{
HB_FHANDLE hFile;
PHB_FILE pFile;
BOOL bRetry, fShared = pArea->fShared && !fTemporary && !fExclusive;
do
{
if( fTemporary )
{
hFile = hb_fsCreateTemp( NULL, NULL, FC_NORMAL, ( BYTE * ) szTempFile );
pFile = hb_fileCreateTemp( NULL, NULL, FC_NORMAL, ( BYTE * ) szTempFile );
fNewFile = TRUE;
}
else
{
hFile = hb_fsExtOpen( ( BYTE * ) szFileName, NULL, FO_READWRITE |
( fShared ? FO_DENYNONE : FO_EXCLUSIVE ) |
( fNewFile ? FXO_TRUNCATE : FXO_APPEND ) |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
pFile = hb_fileExtOpen( ( BYTE * ) szFileName, NULL, FO_READWRITE |
( fShared ? FO_DENYNONE : FO_EXCLUSIVE ) |
( fNewFile ? FXO_TRUNCATE : FXO_APPEND ) |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
}
if( hFile == FS_ERROR )
if( !pFile )
bRetry = ( hb_cdxErrorRT( pArea, EG_CREATE, EDBF_CREATE, szFileName,
hb_fsError(), EF_CANRETRY | EF_CANDEFAULT ) == E_RETRY );
else
{
bRetry = FALSE;
if ( !fNewFile )
fNewFile = ( hb_fsSeekLarge( hFile, 0, FS_END ) == 0 );
if( !fNewFile )
fNewFile = ( hb_fileSize( pFile ) == 0 );
}
}
while ( bRetry );
while( bRetry );
if ( hFile != FS_ERROR )
if( pFile )
{
pIndex = hb_cdxIndexNew( pArea );
pIndex->hFile = hFile;
pIndex->pFile = pFile;
pIndex->fShared = fShared;
pIndex->fReadonly = FALSE;
pIndex->szFileName = hb_strdup( szFileName );
@@ -7651,8 +7644,8 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo
/* TODO: What should be default? */
/*
hb_cdxIndexFree( pIndex );
hb_fsClose( hFile );
hFile = FS_ERROR;
hb_fileClose( pFile );
pFile = NULL;
hb_cdxErrorRT( pArea, EG_CORRUPTION, EDBF_CORRUPT,
szFileName, hb_fsError(), EF_CANDEFAULT );
*/
@@ -7662,7 +7655,7 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo
}
}
if ( hFile == FS_ERROR )
if( !pFile )
{
hb_vmDestroyBlockOrMacro( pKeyExp );
if ( pForExp != NULL )
@@ -7681,8 +7674,7 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo
if ( fNewFile )
{
hb_fsSeek( pIndex->hFile, 0, FS_SET );
hb_fsWrite( pIndex->hFile, NULL, 0 );
hb_fileTruncAt( pIndex->pFile, 0 );
pIndex->fChanged = TRUE;
hb_cdxIndexDropAvailPage( pIndex );
if ( pIndex->pCompound != NULL )
@@ -8193,7 +8185,8 @@ static ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO pI
break;
case DBOI_FILEHANDLE:
pInfo->itmResult = hb_itemPutNInt( pInfo->itmResult, ( HB_NHANDLE ) ( pTag ? pTag->pIndex->hFile : FS_ERROR ) );
pInfo->itmResult = hb_itemPutNInt( pInfo->itmResult, ( HB_NHANDLE )
( pTag ? hb_fileHandle( pTag->pIndex->pFile ) : FS_ERROR ) );
break;
case DBOI_ISCOND:
@@ -9426,11 +9419,10 @@ static void hb_cdxTagDoIndex( LPCDXTAG pTag, BOOL fReindex )
iRec = ulRecCount - ulRecNo + 1;
if( ulNextCount > 0 && ulNextCount < ( ULONG ) iRec )
iRec = ( int ) ulNextCount;
hb_fsSeekLarge( pArea->hDataFile,
( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen, FS_SET );
hb_fsReadLarge( pArea->hDataFile, pSort->pRecBuff, pArea->uiRecordLen * iRec );
hb_fileReadAt( pArea->pDataFile, pSort->pRecBuff, pArea->uiRecordLen * iRec,
( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen );
iRecBuff = 0;
}
pArea->pRecord = pSort->pRecBuff + iRecBuff * pArea->uiRecordLen;

File diff suppressed because it is too large Load Diff

View File

@@ -903,9 +903,8 @@ static BOOL hb_ntxBlockRead( LPNTXINDEX pIndex, ULONG ulBlock, BYTE *buffer, int
#ifdef HB_NTX_DEBUG_DISP
s_rdNO++;
#endif
hb_fsSeekLarge( pIndex->DiskFile,
hb_ntxFileOffset( pIndex, ulBlock ), FS_SET );
if( hb_fsRead( pIndex->DiskFile, buffer, iSize ) != iSize )
if( hb_fileReadAt( pIndex->DiskFile, buffer, iSize,
hb_ntxFileOffset( pIndex, ulBlock ) ) != ( ULONG ) iSize )
{
hb_ntxErrorRT( pIndex->Owner, EG_READ, EDBF_READ,
pIndex->IndexName, hb_fsError(), 0 );
@@ -925,9 +924,8 @@ static BOOL hb_ntxBlockWrite( LPNTXINDEX pIndex, ULONG ulBlock, BYTE *buffer, in
#ifdef HB_NTX_DEBUG_DISP
s_wrNO++;
#endif
hb_fsSeekLarge( pIndex->DiskFile,
hb_ntxFileOffset( pIndex, ulBlock ), FS_SET );
if( hb_fsWrite( pIndex->DiskFile, buffer, iSize ) != iSize )
if( hb_fileWriteAt( pIndex->DiskFile, buffer, iSize,
hb_ntxFileOffset( pIndex, ulBlock ) ) != ( ULONG ) iSize )
{
hb_ntxErrorRT( pIndex->Owner, EG_WRITE, EDBF_WRITE,
pIndex->IndexName, hb_fsError(), 0 );
@@ -1056,8 +1054,7 @@ static void hb_ntxIndexTrunc( LPNTXINDEX pIndex )
pIndex->Update = pIndex->Changed = pIndex->fFlush = TRUE;
pIndex->TagBlock = pIndex->NextAvail = 0;
pIndex->Version = 0;
hb_fsSeek( pIndex->DiskFile, NTXBLOCKSIZE, FS_SET );
hb_fsWrite( pIndex->DiskFile, NULL, 0 );
hb_fileTruncAt( pIndex->DiskFile, NTXBLOCKSIZE );
}
/*
@@ -1283,7 +1280,7 @@ static ULONG hb_ntxPageAlloc( LPNTXINDEX pIndex )
if( !pIndex->TagBlock )
{
HB_FOFFSET fOffset;
fOffset = hb_fsSeekLarge( pIndex->DiskFile, 0, FS_END );
fOffset = hb_fileSize( pIndex->DiskFile );
pIndex->TagBlock = ( ULONG )
( fOffset >> ( pIndex->LargeFile ? NTXBLOCKBITS : 0 ) );
}
@@ -1750,7 +1747,7 @@ static LPNTXINDEX hb_ntxIndexNew( NTXAREAP pArea )
pIndex = ( LPNTXINDEX ) hb_xgrab( sizeof( NTXINDEX ) );
memset( pIndex, 0, sizeof( NTXINDEX ) );
pIndex->DiskFile = FS_ERROR;
pIndex->DiskFile = NULL;
pIndex->Owner = pArea;
return pIndex;
}
@@ -1770,9 +1767,9 @@ static void hb_ntxIndexFree( LPNTXINDEX pIndex )
}
if( pIndex->HeaderBuff )
hb_xfree( pIndex->HeaderBuff );
if( pIndex->DiskFile != FS_ERROR )
if( pIndex->DiskFile )
{
hb_fsClose( pIndex->DiskFile );
hb_fileClose( pIndex->DiskFile );
if( pIndex->fDelete )
{
hb_fsDelete( ( BYTE * ) ( pIndex->RealName ?
@@ -4665,10 +4662,9 @@ static void hb_ntxSortBufferFlush( LPNTXSORTINFO pSort )
if( pSort->ulPagesIO )
{
LPNTXINDEX pIndex = pSort->pTag->Owner;
hb_fsSeekLarge( pIndex->DiskFile,
hb_ntxFileOffset( pIndex, pSort->ulFirstIO ), FS_SET );
ulSize = pSort->ulPagesIO * NTXBLOCKSIZE;
if( hb_fsWriteLarge( pIndex->DiskFile, pSort->pBuffIO, ulSize ) != ulSize )
if( hb_fileWriteAt( pIndex->DiskFile, pSort->pBuffIO, ulSize,
hb_ntxFileOffset( pIndex, pSort->ulFirstIO ) ) != ulSize )
{
hb_ntxErrorRT( pIndex->Owner, EG_WRITE, EDBF_WRITE,
pIndex->IndexName, hb_fsError(), 0 );
@@ -5366,11 +5362,10 @@ static ERRCODE hb_ntxTagCreate( LPTAGINFO pTag, BOOL fReindex )
iRec = ulRecCount - ulRecNo + 1;
if( ulNextCount > 0 && ulNextCount < ( ULONG ) iRec )
iRec = ( int ) ulNextCount;
hb_fsSeekLarge( pArea->hDataFile,
( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen, FS_SET );
hb_fsReadLarge( pArea->hDataFile, pSort->pBuffIO, pArea->uiRecordLen * iRec );
hb_fileReadAt( pArea->pDataFile, pSort->pBuffIO, pArea->uiRecordLen * iRec,
( HB_FOFFSET ) pArea->uiHeaderLen +
( HB_FOFFSET ) ( ulRecNo - 1 ) *
( HB_FOFFSET ) pArea->uiRecordLen );
iRecBuff = 0;
}
pArea->pRecord = pSort->pBuffIO + iRecBuff * pArea->uiRecordLen;
@@ -5777,7 +5772,7 @@ static ERRCODE ntxFlush( NTXAREAP pArea )
{
if( pIndex->fFlush /* && !pIndex->Temporary */ )
{
hb_fsCommit( pIndex->DiskFile );
hb_fileCommit( pIndex->DiskFile );
pIndex->fFlush = FALSE;
}
pIndex = pIndex->pNext;
@@ -6290,7 +6285,7 @@ static ERRCODE ntxOrderCreate( NTXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo )
}
else
{
HB_FHANDLE hFile;
PHB_FILE pFile;
BOOL bRetry, fOld, fShared = pArea->fShared && !fTemporary && !fExclusive;
USHORT uiFlags = FO_READWRITE | ( fShared ? FO_DENYNONE : FO_EXCLUSIVE );
@@ -6299,29 +6294,29 @@ static ERRCODE ntxOrderCreate( NTXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo )
{
if( fTemporary )
{
hFile = hb_fsCreateTemp( NULL, NULL, FC_NORMAL, ( BYTE * ) szSpFile );
pFile = hb_fileCreateTemp( NULL, NULL, FC_NORMAL, ( BYTE * ) szSpFile );
fOld = FALSE;
}
else
{
hFile = hb_fsExtOpen( ( BYTE * ) szFileName, NULL, uiFlags |
( fOld ? FXO_APPEND : FXO_TRUNCATE ) |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
pFile = hb_fileExtOpen( ( BYTE * ) szFileName, NULL, uiFlags |
( fOld ? FXO_APPEND : FXO_TRUNCATE ) |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
}
if( hFile == FS_ERROR )
if( !pFile )
bRetry = ( hb_ntxErrorRT( pArea, EG_CREATE, EDBF_CREATE, szFileName,
hb_fsError(), EF_CANRETRY | EF_CANDEFAULT ) == E_RETRY );
else
{
bRetry = FALSE;
if( fOld )
fOld = ( hb_fsSeekLarge( hFile, 0, FS_END ) != 0 );
fOld = ( hb_fileSize( pFile ) != 0 );
}
}
while( bRetry );
if( hFile == FS_ERROR )
if( !pFile )
{
hb_vmDestroyBlockOrMacro( pKeyExp );
if( pForExp != NULL )
@@ -6334,7 +6329,7 @@ static ERRCODE ntxOrderCreate( NTXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo )
pIndex->IndexName = hb_strdup( szFileName );
pIndex->fReadonly = FALSE;
pIndex->fShared = fShared;
pIndex->DiskFile = hFile;
pIndex->DiskFile = pFile;
pIndex->fDelete = fTemporary;
if( fTemporary )
pIndex->RealName = hb_strdup( szSpFile );
@@ -6781,7 +6776,8 @@ static ERRCODE ntxOrderInfo( NTXAREAP pArea, USHORT uiIndex, LPDBORDERINFO pInfo
hb_itemPutNI( pInfo->itmResult, hb_ntxFindTagNum( pArea, pTag ) );
break;
case DBOI_FILEHANDLE:
hb_itemPutNInt( pInfo->itmResult, ( HB_NHANDLE ) pTag->Owner->DiskFile );
hb_itemPutNInt( pInfo->itmResult,
( HB_NHANDLE ) hb_fileHandle( pTag->Owner->DiskFile ) );
break;
case DBOI_FULLPATH:
hb_itemPutC( pInfo->itmResult, pTag->Owner->IndexName );
@@ -7249,7 +7245,7 @@ static ERRCODE ntxCountScope( NTXAREAP pArea, void * pPtr, LONG * plRecNo )
static ERRCODE ntxOrderListAdd( NTXAREAP pArea, LPDBORDERINFO pOrderInfo )
{
USHORT uiFlags;
HB_FHANDLE hFile;
PHB_FILE pFile;
char szFileName[ _POSIX_PATH_MAX + 1 ], szTagName[ NTX_MAX_TAGNAME + 1 ];
LPNTXINDEX pIndex, *pIndexPtr;
ERRCODE errCode;
@@ -7283,10 +7279,10 @@ static ERRCODE ntxOrderListAdd( NTXAREAP pArea, LPDBORDERINFO pOrderInfo )
do
{
fRetry = FALSE;
hFile = hb_fsExtOpen( ( BYTE * ) szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
if( hFile == FS_ERROR )
pFile = hb_fileExtOpen( ( BYTE * ) szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, NULL );
if( !pFile )
{
fRetry = ( hb_ntxErrorRT( pArea, EG_OPEN, EDBF_OPEN_INDEX, szFileName,
hb_fsError(), EF_CANRETRY | EF_CANDEFAULT ) == E_RETRY );
@@ -7294,14 +7290,14 @@ static ERRCODE ntxOrderListAdd( NTXAREAP pArea, LPDBORDERINFO pOrderInfo )
}
while( fRetry );
if( hFile == FS_ERROR )
if( !pFile )
return FAILURE;
pIndex = hb_ntxIndexNew( pArea );
pIndex->IndexName = hb_strdup( szFileName );
pIndex->fReadonly = fReadonly;
pIndex->fShared = fShared;
pIndex->DiskFile = hFile;
pIndex->DiskFile = pFile;
pIndex->Production = fProd;
pIndexPtr = &pArea->lpIndexes;

View File

@@ -206,10 +206,10 @@ static int hb_delimNextChar( DELIMAREAP pArea )
pArea->pBuffer + pArea->ulBufferIndex, ulLeft );
pArea->ulBufferStart += pArea->ulBufferIndex;
pArea->ulBufferIndex = 0;
hb_fsSeekLarge( pArea->hFile, pArea->ulBufferStart + ulLeft, FS_SET );
pArea->ulBufferRead = hb_fsReadLarge( pArea->hFile,
pArea->pBuffer + ulLeft,
pArea->ulBufferSize - ulLeft );
pArea->ulBufferRead = hb_fileReadAt( pArea->pFile,
pArea->pBuffer + ulLeft,
pArea->ulBufferSize - ulLeft,
pArea->ulBufferStart + ulLeft );
if( pArea->ulBufferRead > 0 &&
pArea->pBuffer[ pArea->ulBufferRead + ulLeft - 1 ] == '\032' )
pArea->ulBufferRead--;
@@ -814,8 +814,8 @@ static ERRCODE hb_delimGoCold( DELIMAREAP pArea )
{
ULONG ulSize = hb_delimEncodeBuffer( pArea );
hb_fsSeekLarge( pArea->hFile, pArea->ulRecordOffset, FS_SET );
if( hb_fsWriteLarge( pArea->hFile, pArea->pBuffer, ulSize ) != ulSize )
if( hb_fileWriteAt( pArea->pFile, pArea->pBuffer, ulSize,
pArea->ulRecordOffset ) != ulSize )
{
PHB_ITEM pError = hb_errNew();
@@ -872,11 +872,10 @@ static ERRCODE hb_delimFlush( DELIMAREAP pArea )
if( pArea->fFlush )
{
hb_fsSeekLarge( pArea->hFile, pArea->ulFileSize, FS_SET );
hb_fsWrite( pArea->hFile, ( BYTE * ) "\032", 1 );
hb_fileWriteAt( pArea->pFile, ( BYTE * ) "\032", 1, pArea->ulFileSize );
if( hb_setGetHardCommit() )
{
hb_fsCommit( pArea->hFile );
hb_fileCommit( pArea->pFile );
pArea->fFlush = FALSE;
}
}
@@ -975,7 +974,7 @@ static ERRCODE hb_delimInfo( DELIMAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
break;
case DBI_FILEHANDLE:
hb_itemPutNInt( pItem, ( HB_NHANDLE ) pArea->hFile );
hb_itemPutNInt( pItem, ( HB_NHANDLE ) hb_fileHandle( pArea->pFile ) );
break;
case DBI_SHARED:
@@ -1155,7 +1154,7 @@ static ERRCODE hb_delimNewArea( DELIMAREAP pArea )
if( SUPER_NEW( ( AREAP ) pArea ) == FAILURE )
return FAILURE;
pArea->hFile = FS_ERROR;
pArea->pFile = NULL;
pArea->fTransRec = TRUE;
pArea->uiRecordLen = 0;
pArea->ulBufferSize = 0;
@@ -1191,11 +1190,11 @@ static ERRCODE hb_delimClose( DELIMAREAP pArea )
SUPER_CLOSE( ( AREAP ) pArea );
/* Update record and unlock records */
if( pArea->hFile != FS_ERROR )
if( pArea->pFile )
{
SELF_FLUSH( ( AREAP ) pArea );
hb_fsClose( pArea->hFile );
pArea->hFile = FS_ERROR;
hb_fileClose( pArea->pFile );
pArea->pFile = NULL;
}
if( pArea->pFieldOffset )
@@ -1271,11 +1270,11 @@ static ERRCODE hb_delimCreate( DELIMAREAP pArea, LPDBOPENINFO pCreateInfo )
/* Try create */
do
{
pArea->hFile = hb_fsExtOpen( szFileName, NULL,
FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( pArea->hFile == FS_ERROR )
pArea->pFile = hb_fileExtOpen( szFileName, NULL,
FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( !pArea->pFile )
{
if( !pError )
{
@@ -1297,7 +1296,7 @@ static ERRCODE hb_delimCreate( DELIMAREAP pArea, LPDBOPENINFO pCreateInfo )
if( pError )
hb_itemRelease( pError );
if( pArea->hFile == FS_ERROR )
if( !pArea->pFile )
return FAILURE;
errCode = SUPER_CREATE( ( AREAP ) pArea, pCreateInfo );
@@ -1370,10 +1369,10 @@ static ERRCODE hb_delimOpen( DELIMAREAP pArea, LPDBOPENINFO pOpenInfo )
/* Try open */
do
{
pArea->hFile = hb_fsExtOpen( szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( pArea->hFile == FS_ERROR )
pArea->pFile = hb_fileExtOpen( szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( !pArea->pFile )
{
if( !pError )
{
@@ -1395,7 +1394,7 @@ static ERRCODE hb_delimOpen( DELIMAREAP pArea, LPDBOPENINFO pOpenInfo )
if( pError )
hb_itemRelease( pError );
if( pArea->hFile == FS_ERROR )
if( !pArea->pFile )
return FAILURE;
errCode = SUPER_OPEN( ( AREAP ) pArea, pOpenInfo );

File diff suppressed because it is too large Load Diff

View File

@@ -104,9 +104,8 @@ static ERRCODE hb_sdfReadRecord( SDFAREAP pArea )
HB_TRACE(HB_TR_DEBUG, ("hb_sdfReadRecord(%p)", pArea));
uiToRead = pArea->uiRecordLen + pArea->uiEolLen + 2;
hb_fsSeekLarge( pArea->hFile, pArea->ulRecordOffset, FS_SET );
uiRead = hb_fsRead( pArea->hFile, pArea->pRecord, uiToRead );
uiRead = hb_fileReadAt( pArea->pFile, pArea->pRecord, uiToRead,
pArea->ulRecordOffset );
if( uiRead > 0 && uiRead < uiToRead && pArea->pRecord[ uiRead - 1 ] == '\032' )
--uiRead;
@@ -163,15 +162,14 @@ static ERRCODE hb_sdfNextRecord( SDFAREAP pArea )
if( pArea->ulNextOffset == 0 )
{
USHORT uiRead, uiToRead, uiEolPos, uiRest = 0;
HB_FOFFSET ulOffset = 0;
HB_FOFFSET ulOffset = pArea->ulRecordOffset;
uiToRead = pArea->uiRecordLen + pArea->uiEolLen + 2;
hb_fsSeekLarge( pArea->hFile, pArea->ulRecordOffset, FS_SET );
do
{
uiRead = hb_fsRead( pArea->hFile, pArea->pRecord + uiRest,
uiToRead - uiRest ) + uiRest;
uiRead = hb_fileReadAt( pArea->pFile, pArea->pRecord + uiRest,
uiToRead - uiRest, ulOffset + uiRest ) + uiRest;
if( uiRead > 0 && uiRead < uiToRead &&
pArea->pRecord[ uiRead - 1 ] == '\032' )
--uiRead;
@@ -184,8 +182,7 @@ static ERRCODE hb_sdfNextRecord( SDFAREAP pArea )
if( uiRead == pArea->uiRecordLen + pArea->uiEolLen )
pArea->ulNextOffset = ( HB_FOFFSET ) -1;
else
pArea->ulNextOffset = pArea->ulRecordOffset + ulOffset +
uiEolPos + pArea->uiEolLen;
pArea->ulNextOffset = ulOffset + uiEolPos + pArea->uiEolLen;
}
else if( uiRead < uiToRead )
{
@@ -637,10 +634,10 @@ static ERRCODE hb_sdfGoCold( SDFAREAP pArea )
if( pArea->fRecordChanged )
{
USHORT uiWrite = pArea->uiRecordLen + pArea->uiEolLen;
ULONG ulWrite = pArea->uiRecordLen + pArea->uiEolLen;
hb_fsSeekLarge( pArea->hFile, pArea->ulRecordOffset, FS_SET );
if( hb_fsWrite( pArea->hFile, pArea->pRecord, uiWrite ) != uiWrite )
if( hb_fileWriteAt( pArea->pFile, pArea->pRecord, ulWrite,
pArea->ulRecordOffset ) != ulWrite )
{
PHB_ITEM pError = hb_errNew();
@@ -653,7 +650,7 @@ static ERRCODE hb_sdfGoCold( SDFAREAP pArea )
hb_itemRelease( pError );
return FAILURE;
}
pArea->ulFileSize += uiWrite;
pArea->ulFileSize += ulWrite;
pArea->ulNextOffset = pArea->ulFileSize;
pArea->fRecordChanged = FALSE;
pArea->fFlush = TRUE;
@@ -697,11 +694,10 @@ static ERRCODE hb_sdfFlush( SDFAREAP pArea )
if( pArea->fFlush )
{
hb_fsSeekLarge( pArea->hFile, pArea->ulFileSize, FS_SET );
hb_fsWrite( pArea->hFile, ( BYTE * ) "\032", 1 );
hb_fileWriteAt( pArea->pFile, ( BYTE * ) "\032", 1, pArea->ulFileSize );
if( hb_setGetHardCommit() )
{
hb_fsCommit( pArea->hFile );
hb_fileCommit( pArea->pFile );
pArea->fFlush = FALSE;
}
}
@@ -731,7 +727,7 @@ static ERRCODE hb_sdfInfo( SDFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
break;
case DBI_FILEHANDLE:
hb_itemPutNInt( pItem, ( HB_NHANDLE ) pArea->hFile );
hb_itemPutNInt( pItem, ( HB_NHANDLE ) hb_fileHandle( pArea->pFile ) );
break;
case DBI_SHARED:
@@ -904,7 +900,7 @@ static ERRCODE hb_sdfNewArea( SDFAREAP pArea )
if( SUPER_NEW( ( AREAP ) pArea ) == FAILURE )
return FAILURE;
pArea->hFile = FS_ERROR;
pArea->pFile = NULL;
pArea->fTransRec = TRUE;
pArea->uiRecordLen = 0;
@@ -933,11 +929,11 @@ static ERRCODE hb_sdfClose( SDFAREAP pArea )
SUPER_CLOSE( ( AREAP ) pArea );
/* Update record and unlock records */
if( pArea->hFile != FS_ERROR )
if( pArea->pFile )
{
SELF_FLUSH( ( AREAP ) pArea );
hb_fsClose( pArea->hFile );
pArea->hFile = FS_ERROR;
hb_fileClose( pArea->pFile );
pArea->pFile = NULL;
}
if( pArea->pFieldOffset )
@@ -1008,11 +1004,11 @@ static ERRCODE hb_sdfCreate( SDFAREAP pArea, LPDBOPENINFO pCreateInfo )
/* Try create */
do
{
pArea->hFile = hb_fsExtOpen( szFileName, NULL,
FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( pArea->hFile == FS_ERROR )
pArea->pFile = hb_fileExtOpen( szFileName, NULL,
FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( !pArea->pFile )
{
if( !pError )
{
@@ -1034,7 +1030,7 @@ static ERRCODE hb_sdfCreate( SDFAREAP pArea, LPDBOPENINFO pCreateInfo )
if( pError )
hb_itemRelease( pError );
if( pArea->hFile == FS_ERROR )
if( !pArea->pFile )
return FAILURE;
errCode = SUPER_CREATE( ( AREAP ) pArea, pCreateInfo );
@@ -1107,10 +1103,10 @@ static ERRCODE hb_sdfOpen( SDFAREAP pArea, LPDBOPENINFO pOpenInfo )
/* Try open */
do
{
pArea->hFile = hb_fsExtOpen( szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( pArea->hFile == FS_ERROR )
pArea->pFile = hb_fileExtOpen( szFileName, NULL, uiFlags |
FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME,
NULL, pError );
if( !pArea->pFile )
{
if( !pError )
{
@@ -1132,7 +1128,7 @@ static ERRCODE hb_sdfOpen( SDFAREAP pArea, LPDBOPENINFO pOpenInfo )
if( pError )
hb_itemRelease( pError );
if( pArea->hFile == FS_ERROR )
if( pArea->pFile )
return FAILURE;
errCode = SUPER_OPEN( ( AREAP ) pArea, pOpenInfo );

View File

@@ -34,6 +34,7 @@ C_SOURCES=\
errorapu.c \
errorint.c \
file.c \
filebuf.c \
filehb.c \
filesys.c \
fkmax.c \

View File

@@ -0,0 +1,500 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* functions to access files with shared handles and locks
* (buffers in the future)
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
/* this has to be declared before hbapifs.h is included */
#define _HB_FILE_INTERNAL_
struct _HB_FILE;
typedef struct _HB_FILE * PHB_FILE;
#include "hbapi.h"
#include "hbapifs.h"
#include "hbapierr.h"
#include "hbthread.h"
#include "hbvm.h"
#if !defined(HB_WINCE)
# include <sys/types.h>
# include <sys/stat.h>
#endif
#define HB_FLOCK_RESIZE 16
typedef struct
{
HB_FOFFSET start;
HB_FOFFSET len;
}
HB_FLOCK, * PHB_FLOCK;
typedef struct _HB_FILE
{
ULONG device;
ULONG inode;
int used;
BOOL shared;
HB_FHANDLE hFile;
PHB_FLOCK pLocks;
UINT uiLocks;
UINT uiSize;
struct _HB_FILE * pNext;
struct _HB_FILE * pPrev;
}
HB_FILE;
static HB_CRITICAL_NEW( s_fileMtx );
static PHB_FILE s_openFiles = NULL;
void hb_fileDsp( PHB_FILE pFile, const char * szMsg )
{
UINT uiPos = 0;
printf( "\r\n[%s][", szMsg );
while( uiPos < pFile->uiLocks )
{
PHB_FLOCK pLock = &pFile->pLocks[ uiPos ];
printf( "%lld:%lld ", pLock->start, pLock->len );
++uiPos;
}
printf( "]" );
fflush(stdout);
}
static PHB_FILE hb_fileFind( ULONG device, ULONG inode )
{
if( s_openFiles && ( device || inode ) )
{
PHB_FILE pFile = s_openFiles;
do
{
if( pFile->device == device && pFile->inode == inode )
return pFile;
pFile = pFile->pNext;
}
while( s_openFiles != pFile );
}
return NULL;
}
static PHB_FILE hb_fileNew( HB_FHANDLE hFile, BOOL fShared,
ULONG device, ULONG inode, BOOL fBind )
{
PHB_FILE pFile = hb_fileFind( device, inode );
if( !pFile )
{
pFile = ( PHB_FILE ) hb_xgrab( sizeof( HB_FILE ) );
memset( pFile, 0, sizeof( HB_FILE ) );
pFile->device = device;
pFile->inode = inode;
pFile->hFile = hFile;
pFile->shared = fShared;
if( fBind )
{
if( s_openFiles )
{
pFile->pNext = s_openFiles;
pFile->pPrev = s_openFiles->pPrev;
pFile->pPrev->pNext = pFile;
s_openFiles->pPrev = pFile;
}
else
s_openFiles = pFile->pNext = pFile->pPrev = pFile;
}
}
pFile->used++;
return pFile;
}
static UINT hb_fileFindOffset( PHB_FILE pFile, HB_FOFFSET ulOffset )
{
UINT uiFirst, uiLast, uiMiddle;
uiFirst = 0;
uiLast = pFile->uiLocks;
uiMiddle = uiLast >> 1;
while( uiFirst < uiLast )
{
HB_FOFFSET ulEnd = pFile->pLocks[ uiMiddle ].start +
pFile->pLocks[ uiMiddle ].len;
if( ulEnd <= ulOffset )
uiFirst = uiMiddle + 1;
else
uiLast = uiMiddle;
uiMiddle = ( uiFirst + uiLast ) >> 1;
}
return uiMiddle;
}
static void hb_fileInsertLock( PHB_FILE pFile, UINT uiPos,
HB_FOFFSET ulStart, HB_FOFFSET ulLen )
{
if( pFile->uiLocks == pFile->uiSize )
{
pFile->uiSize += HB_FLOCK_RESIZE;
pFile->pLocks = ( PHB_FLOCK ) hb_xrealloc( pFile->pLocks,
sizeof( HB_FLOCK ) * pFile->uiSize );
memset( &pFile->pLocks[ pFile->uiLocks ], 0,
sizeof( HB_FLOCK ) * HB_FLOCK_RESIZE );
}
pFile->uiLocks++;
memmove( &pFile->pLocks[ uiPos + 1 ], &pFile->pLocks[ uiPos ],
( pFile->uiLocks - uiPos ) * sizeof( HB_FLOCK ) );
pFile->pLocks[ uiPos ].start = ulStart;
pFile->pLocks[ uiPos ].len = ulLen;
}
static void hb_fileDeleteLock( PHB_FILE pFile, UINT uiPos )
{
pFile->uiLocks--;
memmove( &pFile->pLocks[ uiPos ], &pFile->pLocks[ uiPos + 1 ],
( pFile->uiLocks - uiPos ) * sizeof( HB_FLOCK ) );
if( pFile->uiSize - pFile->uiLocks >= ( HB_FLOCK_RESIZE << 1 ) )
{
pFile->uiSize -= HB_FLOCK_RESIZE;
pFile->pLocks = ( PHB_FLOCK ) hb_xrealloc( pFile->pLocks,
sizeof( HB_FLOCK ) * pFile->uiSize );
}
}
static BOOL hb_fileSetLock( PHB_FILE pFile, BOOL * pfLockFS,
HB_FOFFSET ulStart, HB_FOFFSET ulLen )
{
BOOL fLJoin, fRJoin;
UINT uiPos;
uiPos = hb_fileFindOffset( pFile, ulStart );
fLJoin = fRJoin = FALSE;
if( uiPos < pFile->uiLocks )
{
PHB_FLOCK pLock = &pFile->pLocks[ uiPos ];
if( ulStart + ulLen > pLock->start )
return FALSE;
if( ulStart + ulLen == pLock->start )
fRJoin = TRUE;
}
if( uiPos > 0 )
{
PHB_FLOCK pLock = &pFile->pLocks[ uiPos - 1 ];
if( pLock->start + pLock->len == ulStart )
fLJoin = TRUE;
}
if( fLJoin )
{
if( fRJoin )
{
pFile->pLocks[ uiPos - 1 ].len += ulLen + pFile->pLocks[ uiPos ].len;
hb_fileDeleteLock( pFile, uiPos );
}
else
pFile->pLocks[ uiPos - 1 ].len += ulLen;
}
else if( fRJoin )
{
pFile->pLocks[ uiPos ].start -= ulLen;
pFile->pLocks[ uiPos ].len += ulLen;
}
else
hb_fileInsertLock( pFile, uiPos, ulStart, ulLen );
if( pFile->shared )
* pfLockFS = TRUE;
return TRUE;
}
static BOOL hb_fileUnlock( PHB_FILE pFile, BOOL * pfLockFS,
HB_FOFFSET ulStart, HB_FOFFSET ulLen )
{
BOOL fResult = FALSE;
UINT uiPos;
uiPos = hb_fileFindOffset( pFile, ulStart );
if( uiPos < pFile->uiLocks )
{
PHB_FLOCK pLock = &pFile->pLocks[ uiPos ];
if( ulStart >= pLock->start &&
ulStart + ulLen <= pLock->start + pLock->len )
{
if( ulStart == pLock->start )
{
if( ulLen == pLock->len )
hb_fileDeleteLock( pFile, uiPos );
else
{
pLock->start += ulLen;
pLock->len -= ulLen;
}
}
else if( ulStart + ulLen == pLock->start + pLock->len )
pLock->len -= ulLen;
else
{
hb_fileInsertLock( pFile, uiPos + 1, ulStart + ulLen,
pLock->start + pLock->len - ulStart - ulLen );
pLock->len = ulStart - pLock->start;
}
if( pFile->shared )
* pfLockFS = TRUE;
fResult = TRUE;
}
}
return fResult;
}
/*
* public API functions
*/
PHB_FILE hb_fileExtOpen( BYTE * pFilename, BYTE * pDefExt,
USHORT uiExFlags, BYTE * pPaths,
PHB_ITEM pError )
{
PHB_FILE pFile = NULL;
#if defined( HB_OS_UNIX )
struct stat statbuf;
BOOL fResult;
#endif
BOOL fShared;
HB_FHANDLE hFile;
BYTE * pszFile;
fShared = ( uiExFlags & ( FO_DENYREAD | FO_DENYWRITE | FO_EXCLUSIVE ) ) == 0;
pszFile = hb_fsExtName( pFilename, pDefExt, uiExFlags, pPaths );
#if defined( HB_OS_UNIX )
hb_vmUnlock();
fResult = stat( ( char * ) pszFile, &statbuf ) == 0;
hb_fsSetIOError( fResult, 0 );
hb_vmLock();
if( fResult )
{
hb_threadEnterCriticalSection( &s_fileMtx );
pFile = hb_fileFind( statbuf.st_dev, statbuf.st_ino );
if( pFile )
{
if( !fShared || ! pFile->shared || ( uiExFlags & FXO_TRUNCATE ) != 0 )
fResult = FALSE;
else
pFile->used++;
}
hb_threadLeaveCriticalSection( &s_fileMtx );
}
if( pFile )
{
if( !fResult )
{
hb_fsSetError( ( uiExFlags & FXO_TRUNCATE ) ? 5 : 32 );
pFile = NULL;
}
else if( uiExFlags & FXO_COPYNAME )
hb_strncpy( ( char * ) pFilename, ( char * ) pszFile, _POSIX_PATH_MAX );
if( pError )
{
hb_errPutFileName( pError, ( char * ) pszFile );
if( !fResult )
{
hb_errPutOsCode( pError, hb_fsError() );
hb_errPutGenCode( pError, ( USHORT ) ( ( uiExFlags & FXO_TRUNCATE ) ? EG_CREATE : EG_OPEN ) );
}
}
}
else
#endif
{
hFile = hb_fsExtOpen( pFilename, pDefExt, uiExFlags, pPaths, pError );
if( hFile != FS_ERROR )
{
ULONG device = 0, inode = 0;
#if defined( HB_OS_UNIX )
hb_vmUnlock();
if( fstat( hFile, &statbuf ) == 0 )
{
device = ( ULONG ) statbuf.st_dev;
inode = ( ULONG ) statbuf.st_ino;
}
hb_fsSetIOError( fResult, 0 );
hb_vmLock();
#endif
hb_threadEnterCriticalSection( &s_fileMtx );
pFile = hb_fileNew( hFile, fShared, device, inode, TRUE );
hb_threadLeaveCriticalSection( &s_fileMtx );
if( pFile->hFile != hFile )
hb_fsClose( hFile );
}
}
hb_xfree( pszFile );
return pFile;
}
void hb_fileClose( PHB_FILE pFile )
{
HB_FHANDLE hFile = FS_ERROR;
hb_threadEnterCriticalSection( &s_fileMtx );
if( --pFile->used == 0 )
{
if( pFile->pNext )
{
pFile->pPrev->pNext = pFile->pNext;
pFile->pNext->pPrev = pFile->pPrev;
if( pFile == s_openFiles )
{
s_openFiles = pFile->pNext;
if( pFile == s_openFiles )
s_openFiles = NULL;
}
}
hFile = pFile->hFile;
if( pFile->pLocks )
hb_xfree( pFile->pLocks );
hb_xfree( pFile );
}
hb_threadLeaveCriticalSection( &s_fileMtx );
if( hFile != FS_ERROR )
hb_fsClose( hFile );
}
BOOL hb_fileLock( PHB_FILE pFile, HB_FOFFSET ulStart, HB_FOFFSET ulLen,
int iType )
{
BOOL fResult, fLockFS = FALSE;
if( ( iType & FL_MASK ) == FL_UNLOCK )
{
hb_threadEnterCriticalSection( &s_fileMtx );
fResult = hb_fileUnlock( pFile, &fLockFS, ulStart, ulLen );
hb_threadLeaveCriticalSection( &s_fileMtx );
if( fLockFS )
hb_fsLockLarge( pFile->hFile, ulStart, ulLen, iType );
}
else
{
hb_threadEnterCriticalSection( &s_fileMtx );
fResult = hb_fileSetLock( pFile, &fLockFS, ulStart, ulLen );
hb_threadLeaveCriticalSection( &s_fileMtx );
if( fLockFS )
{
fResult = hb_fsLockLarge( pFile->hFile, ulStart, ulLen, iType );
if( !fResult )
{
hb_threadEnterCriticalSection( &s_fileMtx );
hb_fileUnlock( pFile, &fLockFS, ulStart, ulLen );
hb_threadLeaveCriticalSection( &s_fileMtx );
}
}
}
return fResult;
}
ULONG hb_fileReadAt( PHB_FILE pFile, BYTE * buffer, ULONG ulSize,
HB_FOFFSET llOffset )
{
return hb_fsReadAt( pFile->hFile, buffer, ulSize, llOffset );
}
ULONG hb_fileWriteAt( PHB_FILE pFile, const BYTE * buffer, ULONG ulSize,
HB_FOFFSET llOffset )
{
return hb_fsWriteAt( pFile->hFile, buffer, ulSize, llOffset );
}
BOOL hb_fileTruncAt( PHB_FILE pFile, HB_FOFFSET llOffset )
{
return hb_fsTruncAt( pFile->hFile, llOffset );
}
HB_FOFFSET hb_fileSize( PHB_FILE pFile )
{
return hb_fsSeekLarge( pFile->hFile, 0, FS_END );
}
void hb_fileCommit( PHB_FILE pFile )
{
hb_fsCommit( pFile->hFile );
}
HB_FHANDLE hb_fileHandle( PHB_FILE pFile )
{
return pFile ? pFile->hFile : FS_ERROR;
}
PHB_FILE hb_fileCreateTemp( const BYTE * pszDir, const BYTE * pszPrefix,
ULONG ulAttr, BYTE * pszName )
{
PHB_FILE pFile = NULL;
HB_FHANDLE hFile;
hFile = hb_fsCreateTemp( pszDir, pszPrefix, ulAttr, pszName );
if( hFile != FS_ERROR )
pFile = hb_fileNew( hFile, FALSE, 0, 0, FALSE );
return pFile;
}

View File

@@ -94,6 +94,9 @@
#if !defined( _LARGEFILE64_SOURCE )
# define _LARGEFILE64_SOURCE
#endif
#if !defined( _XOPEN_SOURCE )
# define _XOPEN_SOURCE 500
#endif
/* OS2 */
#define INCL_DOSFILEMGR /* File Manager values */
@@ -1414,9 +1417,9 @@ HB_EXPORT USHORT hb_fsWrite( HB_FHANDLE hFileHandle, const BYTE * pBuff, USHORT
hb_vmUnlock();
uiWritten = write( hFileHandle, pBuff, uiCount );
hb_fsSetIOError( uiWritten != ( USHORT ) -1, 0 );
hb_vmLock();
if( uiWritten == ( USHORT ) -1 )
uiWritten = 0;
hb_vmLock();
}
else
{
@@ -1426,8 +1429,8 @@ HB_EXPORT USHORT hb_fsWrite( HB_FHANDLE hFileHandle, const BYTE * pBuff, USHORT
#else
hb_fsSetIOError( ftruncate( hFileHandle, lseek( hFileHandle, 0L, SEEK_CUR ) ) != -1, 0 );
#endif
hb_vmLock();
uiWritten = 0;
hb_vmLock();
}
#endif
#else
@@ -1460,6 +1463,8 @@ HB_EXPORT ULONG hb_fsReadLarge( HB_FHANDLE hFileHandle, BYTE * pBuff, ULONG ulCo
hb_vmUnlock();
ulRead = read( hFileHandle, pBuff, ulCount );
hb_fsSetIOError( ulRead != (ULONG) -1, 0 );
if( ulRead == ( ULONG ) -1 )
ulRead = 0;
hb_vmLock();
}
#else
@@ -1547,9 +1552,9 @@ HB_EXPORT ULONG hb_fsWriteLarge( HB_FHANDLE hFileHandle, const BYTE * pBuff, ULO
hb_vmUnlock();
ulWritten = write( hFileHandle, pBuff, ulCount );
hb_fsSetIOError( ulWritten != ( ULONG ) -1, 0 );
hb_vmLock();
if( ulWritten == ( ULONG ) -1 )
ulWritten = 0;
hb_vmLock();
}
#else
{
@@ -1605,8 +1610,8 @@ HB_EXPORT ULONG hb_fsWriteLarge( HB_FHANDLE hFileHandle, const BYTE * pBuff, ULO
#else
hb_fsSetIOError( ftruncate( hFileHandle, lseek( hFileHandle, 0L, SEEK_CUR ) ) != -1, 0 );
#endif
hb_vmLock();
ulWritten = 0;
hb_vmLock();
}
#endif
@@ -1620,6 +1625,163 @@ HB_EXPORT ULONG hb_fsWriteLarge( HB_FHANDLE hFileHandle, const BYTE * pBuff, ULO
return ulWritten;
}
HB_EXPORT ULONG hb_fsReadAt( HB_FHANDLE hFileHandle, BYTE * pBuff, ULONG ulCount, HB_FOFFSET llOffset )
{
ULONG ulRead;
HB_TRACE(HB_TR_DEBUG, ("hb_fsReadAt(%p, %p, %lu, " PFHL ")", hFileHandle, pBuff, ulCount, llOffset));
#if defined(HB_FS_FILE_IO)
#if defined(HB_WIN32_IO)
{
OVERLAPPED Overlapped;
hb_vmUnlock();
memset( &Overlapped, 0, sizeof( Overlapped ) );
Overlapped.Offset = ( DWORD ) ( llOffset & 0xFFFFFFFF ),
Overlapped.OffsetHigh = ( DWORD ) ( llOffset >> 32 ),
hb_fsSetIOError( ReadFile( DosToWinHandle( hFileHandle ),
pBuff, ulCount, &ulRead, &Overlapped ), 0 );
hb_vmLock();
}
#elif defined(HB_OS_UNIX)
{
hb_vmUnlock();
#if defined(HB_USE_LARGEFILE64)
ulRead = pread64( hFileHandle, pBuff, ulCount, llOffset );
#else
ulRead = pread( hFileHandle, pBuff, ulCount, llOffset );
#endif
hb_fsSetIOError( ulRead != (ULONG) -1, 0 );
if( ulRead == ( ULONG ) -1 )
ulRead = 0;
hb_vmLock();
}
#else
{
hb_vmUnlock();
/* TOFIX: this is not atom operation. It has to be fixed for RDD
* file access with shared file handles in aliased work areas
*/
if( hb_fsSeekLarge( hFileHandle, llOffset, FS_SET ) == llOffset )
ulRead = hb_fsReadLarge( hFileHandle, pBuff, ulCount );
else
ulRead = 0;
hb_vmLock();
}
#endif
#else
ulRead = 0;
hb_fsSetError( ( USHORT ) FS_ERROR );
#endif
return ulRead;
}
HB_EXPORT ULONG hb_fsWriteAt( HB_FHANDLE hFileHandle, const BYTE * pBuff, ULONG ulCount, HB_FOFFSET llOffset )
{
ULONG ulWritten;
HB_TRACE(HB_TR_DEBUG, ("hb_fsWriteAt(%p, %p, %lu, " PFHL ")", hFileHandle, pBuff, ulCount, llOffset));
#if defined(HB_FS_FILE_IO)
#if defined(HB_WIN32_IO)
{
OVERLAPPED Overlapped;
hb_vmUnlock();
memset( &Overlapped, 0, sizeof( Overlapped ) );
Overlapped.Offset = ( DWORD ) ( llOffset & 0xFFFFFFFF ),
Overlapped.OffsetHigh = ( DWORD ) ( llOffset >> 32 ),
hb_fsSetIOError( WriteFile( DosToWinHandle( hFileHandle ),
pBuff, ulCount, &ulWritten, &Overlapped ), 0 );
hb_vmLock();
}
#elif defined(HB_OS_UNIX)
{
hb_vmUnlock();
#if defined(HB_USE_LARGEFILE64)
ulWritten = pwrite64( hFileHandle, pBuff, ulCount, llOffset );
#else
ulWritten = pwrite( hFileHandle, pBuff, ulCount, llOffset );
#endif
hb_fsSetIOError( ulWritten != (ULONG) -1, 0 );
if( ulWritten == ( ULONG ) -1 )
ulWritten = 0;
hb_vmLock();
}
#else
{
hb_vmUnlock();
/* TOFIX: this is not atom operation. It has to be fixed for RDD
* file access with shared file handles in aliased work areas
*/
if( hb_fsSeekLarge( hFileHandle, llOffset, FS_SET ) == llOffset )
ulWritten = hb_fsWriteLarge( hFileHandle, pBuff, ulCount );
else
ulWritten = 0;
hb_vmLock();
}
#endif
#else
ulWritten = 0;
hb_fsSetError( ( USHORT ) FS_ERROR );
#endif
return ulWritten;
}
HB_EXPORT BOOL hb_fsTruncAt( HB_FHANDLE hFileHandle, HB_FOFFSET llOffset )
{
BOOL fResult;
HB_TRACE(HB_TR_DEBUG, ("hb_fsReadAt(%p," PFHL ")", hFileHandle, llOffset));
#if defined(HB_FS_FILE_IO)
hb_vmUnlock();
#if defined(HB_WIN32_IO)
{
ULONG ulOffsetLow = ( ULONG ) ( llOffset & ULONG_MAX ),
ulOffsetHigh = ( ULONG ) ( llOffset >> 32 );
/* This is not atom operation anyhow if someone want to truncate
* file then he has to made necessary synchronizations in upper level
* code. We have such situation in our RDD drivers and for us such
* version is enough. [druzus]
*/
ulOffsetLow = SetFilePointer( DosToWinHandle( hFileHandle ),
ulOffsetLow, ( PLONG ) &ulOffsetHigh,
( DWORD ) SEEK_SET );
if( ( ( ( HB_FOFFSET ) ulOffsetHigh << 32 ) | ulOffsetLow ) == llOffset )
fResult = SetEndOfFile( DosToWinHandle( hFileHandle ) );
else
fResult = FALSE;
}
#elif defined(HB_USE_LARGEFILE64)
fResult = ftruncate64( hFileHandle, llOffset ) != -1;
#else
fResult = ftruncate( hFileHandle, llOffset ) != -1;
#endif
hb_fsSetIOError( fResult, 0 );
hb_vmLock();
#else
fResult = FALSE;
hb_fsSetError( ( USHORT ) FS_ERROR );
#endif
return fResult;
}
HB_EXPORT void hb_fsCommit( HB_FHANDLE hFileHandle )
{
HB_TRACE(HB_TR_DEBUG, ("hb_fsCommit(%p)", hFileHandle));
@@ -2658,48 +2820,19 @@ HB_EXPORT BYTE hb_fsCurDrv( void )
return ( BYTE ) uiResult; /* Return the drive number, base 0. */
}
/* copied from xHarbour */
HB_EXPORT HB_FHANDLE hb_fsExtOpen( BYTE * pFilename, BYTE * pDefExt,
USHORT uiExFlags, BYTE * pPaths,
PHB_ITEM pError )
/* convert file name for hb_fsExtOpen
* caller must free the returned buffer
*/
HB_EXPORT BYTE * hb_fsExtName( BYTE * pFilename, BYTE * pDefExt,
USHORT uiExFlags, BYTE * pPaths )
{
HB_PATHNAMES * pSearchPath = NULL, * pNextPath;
HB_PATHNAMES * pNextPath;
PHB_FNAME pFilepath;
HB_FHANDLE hFile;
BOOL fIsFile = FALSE;
BYTE * szPath;
USHORT uiFlags;
HB_TRACE(HB_TR_DEBUG, ("hb_fsExtOpen(%s, %s, %hu, %p, %p)", pFilename, pDefExt, uiExFlags, pPaths, pError));
#if 0
#define FXO_TRUNCATE 0x0100 /* Create (truncate if exists) */
#define FXO_APPEND 0x0200 /* Create (append if exists) */
#define FXO_UNIQUE 0x0400 /* Create unique file FO_EXCL ??? */
#define FXO_FORCEEXT 0x0800 /* Force default extension */
#define FXO_DEFAULTS 0x1000 /* Use SET command defaults */
#define FXO_DEVICERAW 0x2000 /* Open devices in raw mode */
/* xHarbour extension */
#define FXO_SHARELOCK 0x4000 /* emulate DOS SH_DENY* mode in POSIX OS */
#define FXO_COPYNAME 0x8000 /* copy final szPath into pFilename */
hb_errGetFileName( pError );
#endif
szPath = ( BYTE * ) hb_xgrab( _POSIX_PATH_MAX + 1 );
uiFlags = uiExFlags & 0xff;
if( uiExFlags & ( FXO_TRUNCATE | FXO_APPEND | FXO_UNIQUE ) )
{
uiFlags |= FO_CREAT;
if( uiExFlags & FXO_UNIQUE )
uiFlags |= FO_EXCL;
#if !defined( HB_USE_SHARELOCKS )
else if( uiExFlags & FXO_TRUNCATE )
uiFlags |= FO_TRUNC;
#endif
}
pFilepath = hb_fsFNameSplit( ( char * ) pFilename );
if( pDefExt && ( ( uiExFlags & FXO_FORCEEXT ) || !pFilepath->szExtension ) )
@@ -2739,6 +2872,7 @@ HB_EXPORT HB_FHANDLE hb_fsExtOpen( BYTE * pFilename, BYTE * pDefExt,
}
else if( pPaths && *pPaths )
{
HB_PATHNAMES * pSearchPath = NULL;
hb_fsAddSearchPath( ( char * ) pPaths, &pSearchPath );
pNextPath = pSearchPath;
while( !fIsFile && pNextPath )
@@ -2761,6 +2895,47 @@ HB_EXPORT HB_FHANDLE hb_fsExtOpen( BYTE * pFilename, BYTE * pDefExt,
}
hb_xfree( pFilepath );
return szPath;
}
HB_EXPORT HB_FHANDLE hb_fsExtOpen( BYTE * pFilename, BYTE * pDefExt,
USHORT uiExFlags, BYTE * pPaths,
PHB_ITEM pError )
{
HB_FHANDLE hFile;
USHORT uiFlags;
BYTE * szPath;
HB_TRACE(HB_TR_DEBUG, ("hb_fsExtOpen(%s, %s, %hu, %p, %p)", pFilename, pDefExt, uiExFlags, pPaths, pError));
#if 0
#define FXO_TRUNCATE 0x0100 /* Create (truncate if exists) */
#define FXO_APPEND 0x0200 /* Create (append if exists) */
#define FXO_UNIQUE 0x0400 /* Create unique file FO_EXCL ??? */
#define FXO_FORCEEXT 0x0800 /* Force default extension */
#define FXO_DEFAULTS 0x1000 /* Use SET command defaults */
#define FXO_DEVICERAW 0x2000 /* Open devices in raw mode */
/* Harbour extension */
#define FXO_SHARELOCK 0x4000 /* emulate DOS SH_DENY* mode in POSIX OS */
#define FXO_COPYNAME 0x8000 /* copy final szPath into pFilename */
hb_errGetFileName( pError );
#endif
szPath = hb_fsExtName( pFilename, pDefExt, uiExFlags, pPaths );
uiFlags = uiExFlags & 0xff;
if( uiExFlags & ( FXO_TRUNCATE | FXO_APPEND | FXO_UNIQUE ) )
{
uiFlags |= FO_CREAT;
if( uiExFlags & FXO_UNIQUE )
uiFlags |= FO_EXCL;
#if !defined( HB_USE_SHARELOCKS )
else if( uiExFlags & FXO_TRUNCATE )
uiFlags |= FO_TRUNC;
#endif
}
hFile = hb_fsOpen( szPath, uiFlags );
#if defined( HB_USE_SHARELOCKS )

View File

@@ -114,6 +114,8 @@ void hb_releaseCPU( void )
{
HB_TRACE(HB_TR_DEBUG, ("hb_releaseCPU()"));
hb_vmUnlock();
/* TODO: Add code to release time slices on all platforms */
#if defined(HB_OS_WIN_32) || defined(__CYGWIN__)
@@ -174,6 +176,8 @@ void hb_releaseCPU( void )
/* Do nothing */
#endif
hb_vmLock();
}
/* performs all tasks defined for idle state */
@@ -185,9 +189,7 @@ void hb_idleState( void )
{
pIdleData->fIamIdle = TRUE;
hb_vmUnlock();
hb_releaseCPU();
hb_vmLock();
if( hb_vmRequestQuery() == 0 )
{
if( pIdleData->fCollectGarbage )

113
harbour/tests/aliaslck.prg Normal file
View File

@@ -0,0 +1,113 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* demonstration/test code for file lock synchronization between
* aliased work areas
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org
*
*/
proc main()
local cFile := "_tst"
if !dbExists( cFile )
dbCreate( cFile, {{"F","C",10,0}} )
use _tst exclusive
while lastRec() < 100
dbAppend()
enddo
close
endif
? "Test exclusive access"
select 1
use _tst exclusive alias tst1
? "neterr->", netErr(), "used->", used(), "alias->", alias()
select 2
use _tst exclusive alias tst2
? "neterr->", netErr(), "used->", used(), "alias->", alias()
if used()
? "Error, exclusive mode in aliased work areas does not work"
else
? "OK"
endif
dbCloseAll()
wait
?
? "Test shared access"
select 1
use _tst shared alias tst1
? "neterr->", netErr(), "used->", used(), "alias->", alias()
setLock(2)
setLock(4)
setLock(6)
setLock(7)
dspLock()
select 2
use _tst shared alias tst2
? "neterr->", netErr(), "used->", used(), "alias->", alias()
setLock(1)
setLock(2)
setLock(3)
setLock(4)
setLock(5)
setLock(6)
setLock(7)
setLock(8)
setLock(9)
dspLock()
wait
?
select 1
? "unlock all in", alias()
dbUnLock()
dspLock()
select 2
? "lock 10 records in", alias()
setLock(1)
setLock(2)
setLock(3)
setLock(4)
setLock(5)
setLock(6)
setLock(7)
setLock(8)
setLock(9)
dspLock()
wait
?
? "unlock 3, 5, 9 in", alias()
dbRUnLock(3)
dbRUnLock(5)
dbRUnLock(9)
dspLock()
select 1
? "lock 10 records in", alias()
setLock(1)
setLock(2)
setLock(3)
setLock(4)
setLock(5)
setLock(6)
setLock(7)
setLock(8)
setLock(9)
dspLock()
wait
return
proc setLock( n )
? "locking record: " + ltrim( str( n ) ) + " ->", dbRLock( n )
return
proc dspLock()
local n
? alias(), "active locks:"
for each n in dbRLockList()
?? "", ltrim( str( n ) )
next
return

48
harbour/tests/hsxtest.prg Normal file
View File

@@ -0,0 +1,48 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* HiPer-SEEK indexing/search test
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org
*
*/
#include "dbinfo.ch"
//REQUEST RMDBFCDX
PROCEDURE Main()
FIELD FIRST, LAST, STREET, CITY
LOCAL n, hs
if ascan( rddList(1), "RMDBFCDX" ) != 0
rddSetDefault( "RMDBFCDX" )
endif
use test shared
hs := HS_INDEX( "test", "FIRST+LAST+STREET+CITY", 2, 0, , .T., 3 )
/* Look for all records which have 'SHERMAN' string inside */
HS_SET( hs, "SHERMAN" )
while ( n := HS_NEXT( hs ) ) > 0
dbgoto( n )
if HS_VERIFY( hs ) > 0
? rtrim( FIRST+LAST+STREET+CITY )
endif
enddo
wait
/* Does RDD support Record Map Filters? */
if dbinfo( DBI_RM_SUPPORTED )
/* if yest then let set filter for all records with 'SHERMAN'
word and look at them in browser */
HS_FILTER( hs, "SHERMAN" )
dbgotop()
browse()
endif
HS_CLOSE( hs )
RETURN

View File

@@ -4,8 +4,7 @@
/*
* Harbour Project source code:
* demonstration/test code for terminal character output and codepage
* translations
* RDD tests
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org

View File

@@ -4,8 +4,7 @@
/*
* Harbour Project source code:
* demonstration/test code for terminal character output and codepage
* translations
* RDD tests
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org

View File

@@ -4,8 +4,7 @@
/*
* Harbour Project source code:
* demonstration/test code for terminal character output and codepage
* translations
* RDD tests
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org

View File

@@ -4,8 +4,7 @@
/*
* Harbour Project source code:
* demonstration/test code for terminal character output and codepage
* translations
* RDD tests
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org

View File

@@ -4,8 +4,7 @@
/*
* Harbour Project source code:
* demonstration/test code for terminal character output and codepage
* translations
* RDD tests
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org

View File

@@ -4,8 +4,7 @@
/*
* Harbour Project source code:
* demonstration/test code for terminal character output and codepage
* translations
* RDD tests
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org

View File

@@ -4,8 +4,7 @@
/*
* Harbour Project source code:
* demonstration/test code for terminal character output and codepage
* translations
* RDD tests
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org

View File

@@ -4,8 +4,7 @@
/*
* Harbour Project source code:
* demonstration/test code for terminal character output and codepage
* translations
* RDD tests
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org