示例#1
0
文件: ctstrfil.c 项目: NaldoDj/core
static HB_SIZE ct_StrFile( const char * pFileName, const char * pcStr, HB_SIZE nLen,
                           HB_BOOL bOverwrite, HB_FOFFSET nOffset, HB_BOOL bTrunc )
{
   HB_FHANDLE hFile;
   HB_BOOL bOpen = HB_FALSE;
   HB_BOOL bFile = hb_fsFile( pFileName );
   HB_SIZE nWrite = 0;

   if( bFile && bOverwrite )
   {
      hFile = hb_fsOpen( pFileName, FO_READWRITE );
      bOpen = HB_TRUE;
   }
   else if( ! bFile || ! ct_getsafety() )
      hFile = hb_fsCreate( pFileName, ct_getfcreate() );
   else
      hFile = FS_ERROR;

   if( hFile != FS_ERROR )
   {
      if( nOffset )
         hb_fsSeekLarge( hFile, nOffset, FS_SET );
      else if( bOpen )
         hb_fsSeek( hFile, 0, FS_END );

      nWrite = hb_fsWriteLarge( hFile, pcStr, nLen );
      if( ( nWrite == nLen ) && bOpen && bTrunc )
         hb_fsWrite( hFile, NULL, 0 );

      hb_fsClose( hFile );
   }
   return nWrite;
}
示例#2
0
static HB_SIZE ct_StrFile( const char * pFileName, const char * pcStr, HB_SIZE nLen,
                           HB_BOOL bAppend, HB_FOFFSET nOffset, HB_BOOL bTrunc )
{
   HB_SIZE nWrite = 0;
   HB_BOOL bFile = hb_fileExists( pFileName, NULL );

   PHB_FILE hFile = hb_fileExtOpen( pFileName, NULL,
                                    FO_WRITE | FO_PRIVATE |
                                    FXO_SHARELOCK |
                                    ( bAppend ? FXO_APPEND : FXO_TRUNCATE ) |
                                    ( ct_getsafety() ? FXO_UNIQUE : 0 ),
                                    NULL, NULL );

   if( hFile )
   {
      if( ! bFile )
         hb_fileAttrSet( pFileName, ct_getfcreate() );

      if( nOffset )
         hb_fileSeek( hFile, nOffset, FS_SET );
      else
         hb_fileSeek( hFile, 0, FS_END );

      nWrite = hb_fileResult( hb_fileWrite( hFile, pcStr, nLen, -1 ) );
      if( nWrite == nLen && bTrunc )
         hb_fileWrite( hFile, NULL, 0, -1 );

      hb_fileClose( hFile );
   }
   return nWrite;
}