From 786ba57352baad433dbfa77d119f86d21888c54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Mon, 26 May 2014 16:15:46 +0200 Subject: [PATCH] 2014-05-26 16:15 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/common/hbfsapi.c * src/rtl/filesys.c * src/rtl/filebuf.c * contrib/hbmzip/mzip.c * contrib/xhb/filestat.c ! if available always use stat64() instead of stat() in *nixes builds. On 32-bit platforms stat() fails for larger files (>2GB). It should fix problem reported by Lorenzo. --- ChangeLog.txt | 10 ++++++++++ contrib/hbmzip/mzip.c | 25 +++++++++++++++++++++++-- contrib/xhb/filestat.c | 23 ++++++++++++++++++++++- src/common/hbfsapi.c | 35 ++++++++++++++++++++++++++++++++++- src/rtl/filebuf.c | 28 ++++++++++++++++++++++++++++ src/rtl/filesys.c | 34 +++++++++++++++++++++++----------- 6 files changed, 140 insertions(+), 15 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 8d96bb1445..238db51c98 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,16 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-05-26 16:15 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/common/hbfsapi.c + * src/rtl/filesys.c + * src/rtl/filebuf.c + * contrib/hbmzip/mzip.c + * contrib/xhb/filestat.c + ! if available always use stat64() instead of stat() in *nixes builds. + On 32-bit platforms stat() fails for larger files (>2GB). + It should fix problem reported by Lorenzo. + 2014-05-23 17:01 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rtl/filebuf.c ! fixed bad typo inside hb_fileIsLocalName() - result was reverted. diff --git a/contrib/hbmzip/mzip.c b/contrib/hbmzip/mzip.c index 9c19217fbb..c6592c498a 100644 --- a/contrib/hbmzip/mzip.c +++ b/contrib/hbmzip/mzip.c @@ -48,6 +48,10 @@ * */ +#if ! defined( _LARGEFILE64_SOURCE ) +# define _LARGEFILE64_SOURCE 1 +#endif + #include "hbapi.h" #include "hbapiitm.h" #include "hbapierr.h" @@ -84,6 +88,19 @@ #include #endif +#if ! defined( HB_USE_LARGEFILE64 ) && defined( HB_OS_UNIX ) + #if defined( __USE_LARGEFILE64 ) + /* + * The macro: __USE_LARGEFILE64 is set when _LARGEFILE64_SOURCE is + * define and efectively enables lseek64/flock64/ftruncate64 functions + * on 32bit machines. + */ + #define HB_USE_LARGEFILE64 + #elif defined( HB_OS_UNIX ) && defined( O_LARGEFILE ) + #define HB_USE_LARGEFILE64 + #endif +#endif + #define _ZIP_FLAG_UNICODE ( 1 << 11 ) /* Language encoding flag (EFS) */ #if defined( HB_OS_UNIX ) @@ -818,12 +835,16 @@ static int hb_zipStoreFile( zipFile hZip, int iParamFileName, int iParamZipName, #elif defined( HB_OS_UNIX ) if( hb_fileIsLocalName( szFileName ) ) { - struct stat statbuf; struct tm st; time_t ftime; char * pszFree; - +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; + if( stat64( hb_fsNameConv( szFileName, &pszFree ), &statbuf ) == 0 ) +# else + struct stat statbuf; if( stat( hb_fsNameConv( szFileName, &pszFree ), &statbuf ) == 0 ) +# endif { if( S_ISDIR( statbuf.st_mode ) ) { diff --git a/contrib/xhb/filestat.c b/contrib/xhb/filestat.c index d59cb7bf81..a330535fe9 100644 --- a/contrib/xhb/filestat.c +++ b/contrib/xhb/filestat.c @@ -52,6 +52,10 @@ #include "hbdate.h" #include "hbapierr.h" +#if ! defined( _LARGEFILE64_SOURCE ) +# define _LARGEFILE64_SOURCE 1 +#endif + #if defined( HB_OS_UNIX ) #include #include @@ -66,6 +70,19 @@ #include "hbwinuni.h" #endif +#if ! defined( HB_USE_LARGEFILE64 ) && defined( HB_OS_UNIX ) + #if defined( __USE_LARGEFILE64 ) + /* + * The macro: __USE_LARGEFILE64 is set when _LARGEFILE64_SOURCE is + * define and efectively enables lseek64/flock64/ftruncate64 functions + * on 32bit machines. + */ + #define HB_USE_LARGEFILE64 + #elif defined( HB_OS_UNIX ) && defined( O_LARGEFILE ) + #define HB_USE_LARGEFILE64 + #endif +#endif + HB_FUNC( FILESTATS ) { HB_BOOL fResult = HB_FALSE; @@ -83,9 +100,13 @@ HB_FUNC( FILESTATS ) #if defined( HB_OS_UNIX ) { +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; + if( stat64( hb_parc( 1 ), &statbuf ) == 0 ) +# else struct stat statbuf; - if( stat( hb_parc( 1 ), &statbuf ) == 0 ) +# endif { /* determine if we can read/write/execute the file */ HB_FATTR usAttr, ushbAttr = 0; diff --git a/src/common/hbfsapi.c b/src/common/hbfsapi.c index d0c3722d24..b7613d93a6 100644 --- a/src/common/hbfsapi.c +++ b/src/common/hbfsapi.c @@ -46,6 +46,10 @@ * */ +#if ! defined( _LARGEFILE64_SOURCE ) +# define _LARGEFILE64_SOURCE 1 +#endif + #include "hbapi.h" #include "hbapifs.h" #include "hb_io.h" @@ -73,6 +77,19 @@ #include #endif +#if ! defined( HB_USE_LARGEFILE64 ) && defined( HB_OS_UNIX ) + #if defined( __USE_LARGEFILE64 ) + /* + * The macro: __USE_LARGEFILE64 is set when _LARGEFILE64_SOURCE is + * define and efectively enables lseek64/flock64/ftruncate64 functions + * on 32bit machines. + */ + #define HB_USE_LARGEFILE64 + #elif defined( HB_OS_UNIX ) && defined( O_LARGEFILE ) + #define HB_USE_LARGEFILE64 + #endif +#endif + /* * Function that adds zero or more paths to a list of pathnames to search */ @@ -323,8 +340,13 @@ HB_BOOL hb_fsNameExists( const char * pszFileName ) fExist = DosQueryPathInfo( ( PCSZ ) pszFileName, FIL_STANDARD, &fs3, sizeof( fs3 ) ) == NO_ERROR; # elif defined( HB_OS_UNIX ) +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; + fExist = stat64( pszFileName, &statbuf ) == 0; +# else struct stat statbuf; fExist = stat( pszFileName, &statbuf ) == 0; +# endif # else int iTODO; /* To force warning */ # endif @@ -379,10 +401,15 @@ HB_BOOL hb_fsFileExists( const char * pszFileName ) &fs3, sizeof( fs3 ) ) == NO_ERROR && ( fs3.attrFile & FILE_DIRECTORY ) == 0; # elif defined( HB_OS_UNIX ) +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; + fExist = stat64( pszFileName, &statbuf ) == 0 && + S_ISREG( statbuf.st_mode ); +# else struct stat statbuf; - fExist = stat( pszFileName, &statbuf ) == 0 && S_ISREG( statbuf.st_mode ); +# endif # else int iTODO; /* To force warning */ # endif @@ -436,9 +463,15 @@ HB_BOOL hb_fsDirExists( const char * pszDirName ) &fs3, sizeof( fs3 ) ) == NO_ERROR && ( fs3.attrFile & FILE_DIRECTORY ) != 0; # elif defined( HB_OS_UNIX ) +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; + fExist = stat64( pszDirName, &statbuf ) == 0 && + S_ISDIR( statbuf.st_mode ); +# else struct stat statbuf; fExist = stat( pszDirName, &statbuf ) == 0 && S_ISDIR( statbuf.st_mode ); +# endif # else int iTODO; /* To force warning */ # endif diff --git a/src/rtl/filebuf.c b/src/rtl/filebuf.c index 36141f0665..1699f8a410 100644 --- a/src/rtl/filebuf.c +++ b/src/rtl/filebuf.c @@ -50,6 +50,10 @@ /* this has to be declared before hbapifs.h is included */ #define _HB_FILE_INTERNAL_ +#if ! defined( _LARGEFILE64_SOURCE ) +# define _LARGEFILE64_SOURCE 1 +#endif + #include "hbapi.h" #include "hbapifs.h" #include "hbapierr.h" @@ -62,6 +66,18 @@ # include #endif +#if ! defined( HB_USE_LARGEFILE64 ) && defined( HB_OS_UNIX ) + #if defined( __USE_LARGEFILE64 ) + /* + * The macro: __USE_LARGEFILE64 is set when _LARGEFILE64_SOURCE is + * define and efectively enables lseek64/flock64/ftruncate64 functions + * on 32bit machines. + */ + #define HB_USE_LARGEFILE64 + #elif defined( HB_OS_UNIX ) && defined( O_LARGEFILE ) + #define HB_USE_LARGEFILE64 + #endif +#endif #define HB_FLOCK_RESIZE 16 @@ -455,7 +471,11 @@ static PHB_FILE s_fileExtOpen( PHB_FILE_FUNCS pFuncs, const char * pszFileName, #if defined( HB_OS_UNIX ) HB_BOOL fResult, fSeek = HB_FALSE; +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; +# else struct stat statbuf; +# endif #endif HB_BOOL fShared, fReadonly; HB_FHANDLE hFile; @@ -469,7 +489,11 @@ static PHB_FILE s_fileExtOpen( PHB_FILE_FUNCS pFuncs, const char * pszFileName, hb_vmUnlock(); #if defined( HB_OS_UNIX ) +# if defined( HB_USE_LARGEFILE64 ) + fResult = stat64( ( char * ) pszFile, &statbuf ) == 0; +# else fResult = stat( ( char * ) pszFile, &statbuf ) == 0; +# endif hb_fsSetIOError( fResult, 0 ); if( fResult ) @@ -525,7 +549,11 @@ static PHB_FILE s_fileExtOpen( PHB_FILE_FUNCS pFuncs, const char * pszFileName, { HB_ULONG device = 0, inode = 0; #if defined( HB_OS_UNIX ) +# if defined( HB_USE_LARGEFILE64 ) + if( fstat64( hFile, &statbuf ) == 0 ) +# else if( fstat( hFile, &statbuf ) == 0 ) +# endif { device = ( HB_ULONG ) statbuf.st_dev; inode = ( HB_ULONG ) statbuf.st_ino; diff --git a/src/rtl/filesys.c b/src/rtl/filesys.c index 183f29e0f7..2d0d7d280a 100644 --- a/src/rtl/filesys.c +++ b/src/rtl/filesys.c @@ -821,8 +821,13 @@ int hb_fsIsPipeOrSock( HB_FHANDLE hPipeHandle ) #if defined( HB_OS_UNIX ) { +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; + if( fstat64( hPipeHandle, &statbuf ) == 0 ) +# else struct stat statbuf; if( fstat( hPipeHandle, &statbuf ) == 0 ) +# endif { if( S_ISFIFO( statbuf.st_mode ) || S_ISSOCK( statbuf.st_mode ) ) return 1; @@ -1383,17 +1388,19 @@ HB_BOOL hb_fsGetFileTime( const char * pszFileName, long * plJulian, long * plMi } #elif defined( HB_OS_UNIX ) || defined( HB_OS_OS2 ) || defined( HB_OS_DOS ) || defined( __GNUC__ ) { - struct stat sStat; char * pszFree; - - pszFileName = hb_fsNameConv( pszFileName, &pszFree ); - - if( stat( pszFileName, &sStat ) == 0 ) +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; + if( stat64( hb_fsNameConv( pszFileName, &pszFree ), &statbuf ) == 0 ) +# else + struct stat statbuf; + if( stat( hb_fsNameConv( pszFileName, &pszFree ), &statbuf ) == 0 ) +# endif { time_t ftime; struct tm ft; - ftime = sStat.st_mtime; + ftime = statbuf.st_mtime; # if defined( HB_HAS_LOCALTIME_R ) localtime_r( &ftime, &ft ); # else @@ -1404,7 +1411,7 @@ HB_BOOL hb_fsGetFileTime( const char * pszFileName, long * plJulian, long * plMi #if defined( HB_OS_LINUX ) && ( defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ defined( __GLIBC__ ) && defined( __GLIBC_MINOR__ ) && \ ( __GLIBC__ > 2 || ( __GLIBC__ == 2 && __GLIBC_MINOR__ >= 6 ) ) - *plMillisec = hb_timeEncode( ft.tm_hour, ft.tm_min, ft.tm_sec, sStat.st_mtim.tv_nsec / 1000000 ); + *plMillisec = hb_timeEncode( ft.tm_hour, ft.tm_min, ft.tm_sec, statbuf.st_mtim.tv_nsec / 1000000 ); #else *plMillisec = hb_timeEncode( ft.tm_hour, ft.tm_min, ft.tm_sec, 0 ); #endif @@ -1495,11 +1502,15 @@ HB_BOOL hb_fsGetAttr( const char * pszFileName, HB_FATTR * pulAttr ) } # elif defined( HB_OS_UNIX ) { - struct stat sStat; - - if( stat( pszFileName, &sStat ) == 0 ) +# if defined( HB_USE_LARGEFILE64 ) + struct stat64 statbuf; + if( stat64( pszFileName, &statbuf ) == 0 ) +# else + struct stat statbuf; + if( stat( pszFileName, &statbuf ) == 0 ) +# endif { - *pulAttr = hb_fsAttrFromRaw( sStat.st_mode ); + *pulAttr = hb_fsAttrFromRaw( statbuf.st_mode ); fResult = HB_TRUE; } hb_fsSetIOError( fResult, 0 ); @@ -2903,6 +2914,7 @@ HB_ULONG hb_fsSeek( HB_FHANDLE hFileHandle, HB_LONG lOffset, HB_USHORT uiFlags ) /* small trick to resolve problem with position reported for directories */ if( ulPos == LONG_MAX && lOffset == 0 && nFlags == SEEK_END ) { + /* we do not need to use fstat64() here on 32 bit platforms, [druzus] */ struct stat st; if( fstat( hFileHandle, &st ) == 0 )