示例#1
0
static HB_BOOL hb_memowrit( HB_BOOL bHandleEOF )
{
   const char * pszFileName = hb_parc( 1 );
   PHB_ITEM pString   = hb_param( 2, HB_IT_STRING );
   HB_BOOL bRetVal    = HB_FALSE;

   if( pszFileName && pString )
   {
      PHB_FILE pFile = hb_fileExtOpen( pszFileName, NULL,
                                       FO_READWRITE | FO_EXCLUSIVE | FO_PRIVATE |
                                       FXO_TRUNCATE | FXO_SHARELOCK | FXO_NOSEEKPOS,
                                       NULL, NULL );

      if( pFile != NULL )
      {
         HB_SIZE nSize = hb_itemGetCLen( pString );

         bRetVal = hb_fileWriteAt( pFile, hb_itemGetCPtr( pString ), nSize, 0 ) == nSize;

         /* NOTE: CA-Cl*pper will add the EOF even if the write failed. [vszakats] */
         /* NOTE: CA-Cl*pper will not return .F. when the EOF could not be written. [vszakats] */
         if( bHandleEOF && bRetVal )  /* if true, then write EOF */
         {
            char cEOF = HB_CHAR_EOF;
            hb_fileWriteAt( pFile, &cEOF, sizeof( char ), nSize );
         }

         hb_fileClose( pFile );
      }
   }

   return bRetVal;
}
示例#2
0
/*
 * Perform a write of WorkArea memory to the data store.
 */
static HB_ERRCODE hb_delimGoCold( DELIMAREAP pArea )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_delimGoCold(%p)", pArea));

   if( pArea->fRecordChanged )
   {
      ULONG ulSize = hb_delimEncodeBuffer( pArea );

      if( hb_fileWriteAt( pArea->pFile, pArea->pBuffer, ulSize,
                          pArea->ulRecordOffset ) != ulSize )
      {
         PHB_ITEM pError = hb_errNew();

         hb_errPutGenCode( pError, EG_WRITE );
         hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_WRITE ) );
         hb_errPutSubCode( pError, EDBF_WRITE );
         hb_errPutOsCode( pError, hb_fsError() );
         hb_errPutFileName( pError, pArea->szFileName );
         SELF_ERROR( ( AREAP ) pArea, pError );
         hb_itemRelease( pError );
         return HB_FAILURE;
      }
      pArea->ulFileSize += ulSize;
      pArea->ulNextOffset = pArea->ulFileSize;
      pArea->fRecordChanged = FALSE;
      pArea->fFlush = TRUE;
   }
   return HB_SUCCESS;
}
示例#3
0
文件: sdf1.c 项目: AmericoBalboa/core
/*
 * Perform a write of WorkArea memory to the data store.
 */
static HB_ERRCODE hb_sdfGoCold( SDFAREAP pArea )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfGoCold(%p)", pArea ) );

   if( pArea->fRecordChanged )
   {
      HB_SIZE nWrite = pArea->uiRecordLen + pArea->uiEolLen;

      if( hb_fileWriteAt( pArea->pFile, pArea->pRecord, nWrite,
                          pArea->nRecordOffset ) != nWrite )
      {
         PHB_ITEM pError = hb_errNew();

         hb_errPutGenCode( pError, EG_WRITE );
         hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_WRITE ) );
         hb_errPutSubCode( pError, EDBF_WRITE );
         hb_errPutOsCode( pError, hb_fsError() );
         hb_errPutFileName( pError, pArea->szFileName );
         SELF_ERROR( &pArea->area, pError );
         hb_itemRelease( pError );
         return HB_FAILURE;
      }
      pArea->nFileSize += nWrite;
      pArea->nNextOffset = pArea->nFileSize;
      pArea->fRecordChanged = HB_FALSE;
      pArea->fFlush = HB_TRUE;
   }
   return HB_SUCCESS;
}
示例#4
0
/* deletes xxx bytes from the current file, beginning at the current record */
static int _del_buff( PFT_TEXT ft_text, HB_ISIZ iLen )
{
   char *     WriteBuff = ( char * ) hb_xgrab( BUFFSIZE );
   HB_FOFFSET fpRead, fpWrite;
   HB_ISIZ    WriteLen;

   /* initialize file pointers */
   fpWrite = ft_text->offset[ ft_text->area ];
   fpRead  = ft_text->offset[ ft_text->area ] + iLen;

   /* do initial load of buffer */
   WriteLen = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], WriteBuff, BUFFSIZE, fpRead ) );
   fpRead  += WriteLen;

   ft_text->error[ ft_text->area ] = 0;

   while( WriteLen > 0 )
   {
      HB_ISIZ SaveLen;

      /* position to beginning of write area */
      SaveLen = hb_fileResult( hb_fileWriteAt( ft_text->handles[ ft_text->area ], WriteBuff, WriteLen, fpWrite ) );

      /* move write pointer */
      fpWrite += SaveLen;

      if( SaveLen != WriteLen )
      {
         /* error, fetch errcode and quit */
         ft_text->error[ ft_text->area ] = hb_fsError();
         break;
      }

      /* return to read area and read another buffer */
      WriteLen = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], WriteBuff, BUFFSIZE, fpRead ) );
      fpRead  += WriteLen;
   }

   /* store length in bytes, set legacy EOF marker */
   ft_text->lastbyte[ ft_text->area ] = hb_fileSeek( ft_text->handles[ ft_text->area ], fpWrite, FS_SET );
   hb_fileWrite( ft_text->handles[ ft_text->area ], WriteBuff, 0, -1 );

   /* clear last_rec so next gobot will recount the records */
   ft_text->last_rec[ ft_text->area ] = 0;
   hb_fileSeek( ft_text->handles[ ft_text->area ], ft_text->offset[ ft_text->area ], FS_SET );

   hb_xfree( WriteBuff );

   return ft_text->error[ ft_text->area ];
}
示例#5
0
/*
 * Write data buffer to the data store.
 */
static HB_ERRCODE hb_delimFlush( DELIMAREAP pArea )
{
   HB_ERRCODE uiError;

   HB_TRACE(HB_TR_DEBUG, ("hb_delimFlush(%p)", pArea));

   uiError = SELF_GOCOLD( ( AREAP ) pArea );

   if( pArea->fFlush )
   {
      hb_fileWriteAt( pArea->pFile, ( BYTE * ) "\032", 1, pArea->ulFileSize );
      if( hb_setGetHardCommit() )
      {
         hb_fileCommit( pArea->pFile );
         pArea->fFlush = FALSE;
      }
   }

   return uiError;
}
示例#6
0
文件: sdf1.c 项目: AmericoBalboa/core
/*
 * Write data buffer to the data store.
 */
static HB_ERRCODE hb_sdfFlush( SDFAREAP pArea )
{
   HB_ERRCODE errCode;

   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfFlush(%p)", pArea ) );

   errCode = SELF_GOCOLD( &pArea->area );

   if( pArea->fFlush )
   {
      if( hb_setGetEOF() )
         hb_fileWriteAt( pArea->pFile, "\032", 1, pArea->nFileSize );
      if( hb_setGetHardCommit() )
      {
         hb_fileCommit( pArea->pFile );
         pArea->fFlush = HB_FALSE;
      }
   }

   return errCode;
}