From 78c1d987db8c91170b2fb588922ce0e9da103e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Fri, 31 Jul 2015 14:51:22 +0200 Subject: [PATCH] 2015-07-31 14:51 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) 2015-07-31 14:04 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com) * include/hbapifs.h * src/rtl/filebuf.c * src/rtl/vfile.c + add C-level hb_fileSizeGet() function * update HB_VFSIZE() to use hb_fileSizeGet() when passed a filename It means now HB_VFSIZE() works for non-virtual filenames just like HB_FSIZE() did. --- ChangeLog.txt | 10 ++++++++++ include/hbapifs.h | 1 + src/rtl/filebuf.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/rtl/vfile.c | 38 ++------------------------------------ 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index be7b6ec68a..0f614d7cc9 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,16 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2015-07-31 14:51 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) +2015-07-31 14:04 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com) + * include/hbapifs.h + * src/rtl/filebuf.c + * src/rtl/vfile.c + + add C-level hb_fileSizeGet() function + * update HB_VFSIZE() to use hb_fileSizeGet() when passed a filename + It means now HB_VFSIZE() works for non-virtual filenames + just like HB_FSIZE() did. + 2015-07-28 01:39 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rtl/padx.c ! fixed typo in hb_UPad[LRC]() functions - thanks to Grigory Filatov diff --git a/include/hbapifs.h b/include/hbapifs.h index 48e940ada1..f4dffc6e7a 100644 --- a/include/hbapifs.h +++ b/include/hbapifs.h @@ -374,6 +374,7 @@ extern HB_EXPORT HB_BOOL hb_fileDirRemove ( const char * pszDirName ); extern HB_EXPORT double hb_fileDirSpace ( const char * pszDirName, HB_USHORT uiType ); extern HB_EXPORT PHB_ITEM hb_fileDirectory ( const char * pszDirSpec, const char * pszAttr ); +extern HB_EXPORT HB_FOFFSET hb_fileSizeGet ( const char * pszFileName, HB_BOOL bUseDirEntry ); extern HB_EXPORT HB_BOOL hb_fileTimeGet ( const char * pszFileName, long * plJulian, long * plMillisec ); extern HB_EXPORT HB_BOOL hb_fileTimeSet ( const char * pszFileName, long lJulian, long lMillisec ); extern HB_EXPORT HB_BOOL hb_fileAttrGet ( const char * pszFileName, HB_FATTR * pulAttr ); diff --git a/src/rtl/filebuf.c b/src/rtl/filebuf.c index 3955a0d10b..f15b514326 100644 --- a/src/rtl/filebuf.c +++ b/src/rtl/filebuf.c @@ -57,8 +57,10 @@ #include "hbapi.h" #include "hbapifs.h" #include "hbapierr.h" +#include "hbapiitm.h" #include "hbthread.h" #include "hbvm.h" +#include "directry.ch" #if defined( HB_OS_UNIX ) # include @@ -1201,6 +1203,49 @@ HB_BOOL hb_fileTimeSet( const char * pszFileName, long lJulian, long lMillisec ) return hb_fsSetFileTime( pszFileName, lJulian, lMillisec ); } +HB_EXPORT HB_FOFFSET hb_fileSizeGet( const char * pszFileName, HB_BOOL bUseDirEntry ) +{ + int i = s_fileFindDrv( pszFileName ); + + if( i >= 0 ) + { + HB_ERRCODE uiError; + HB_FOFFSET nSize = 0; + + if( bUseDirEntry ) + { + PHB_ITEM pDir = hb_fileDirectory( pszFileName, "HS" ); + + uiError = hb_fsError(); + if( pDir ) + { + PHB_ITEM pEntry = hb_arrayGetItemPtr( pDir, 1 ); + + if( pEntry ) + nSize = hb_arrayGetNInt( pEntry, F_SIZE ); + hb_itemRelease( pDir ); + } + } + else + { + PHB_FILE pFile = hb_fileExtOpen( pszFileName, NULL, FO_READ | FO_COMPAT, NULL, NULL ); + if( pFile ) + { + nSize = hb_fileSize( pFile ); + uiError = hb_fsError(); + hb_fileClose( pFile ); + } + else + uiError = hb_fsError(); + } + hb_fsSetFError( uiError ); + + return nSize; + } + + return hb_fsFSize( pszFileName, bUseDirEntry ); +} + HB_BOOL hb_fileAttrGet( const char * pszFileName, HB_FATTR * pulAttr ) { int i = s_fileFindDrv( pszFileName ); diff --git a/src/rtl/vfile.c b/src/rtl/vfile.c index d2d3ed0583..6b6601bd4a 100644 --- a/src/rtl/vfile.c +++ b/src/rtl/vfile.c @@ -51,7 +51,6 @@ #include "hbapierr.h" #include "hbapiitm.h" #include "hbdate.h" -#include "directry.ch" /* extended FILE IO handle destructor */ static HB_GARBAGE_FUNC( hb_file_Destructor ) @@ -750,45 +749,12 @@ HB_FUNC( HB_VFTRUNC ) HB_FUNC( HB_VFSIZE ) { const char * pszFile = hb_parc( 1 ); - PHB_FILE pFile; if( pszFile ) - { - HB_ERRCODE uiError; - HB_FOFFSET nSize = 0; - - if( hb_parldef( 2, 1 ) ) - { - PHB_ITEM pDir = hb_fileDirectory( pszFile, "HS" ); - - uiError = hb_fsError(); - if( pDir ) - { - PHB_ITEM pEntry = hb_arrayGetItemPtr( pDir, 1 ); - - if( pEntry ) - nSize = hb_arrayGetNInt( pEntry, F_SIZE ); - hb_itemRelease( pDir ); - } - } - else - { - pFile = hb_fileExtOpen( pszFile, NULL, FO_READ | FO_COMPAT, NULL, NULL ); - if( pFile ) - { - nSize = hb_fileSize( pFile ); - uiError = hb_fsError(); - hb_fileClose( pFile ); - } - else - uiError = hb_fsError(); - } - hb_fsSetFError( uiError ); - hb_retnint( nSize ); - } + hb_retnint( hb_fileSizeGet( pszFile, hb_parldef( 2, 1 ) ) ); else { - pFile = hb_fileParam( 1 ); + PHB_FILE pFile = hb_fileParam( 1 ); if( pFile ) { hb_retnint( hb_fileSize( pFile ) );