From 47ed35ee5cae88a5cdedb5d02d11e145c07cbb5f Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 22 Oct 2008 15:45:36 +0000 Subject: [PATCH] 2008-10-22 17:45 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/bin/hbmk.bat * simple modification to make beginning hbmk parameters (-mt and -gui) position independent though they still have to be used before Harbour/ C compiler switches and filenames * harbour/source/common/hbdate.c * harbour/source/compiler/cmdcheck.c * harbour/source/rtl/filesys.c * harbour/source/rtl/hbffind.c ! use MT safe localtime_r() function if it's available instead of localtime() TODO: clean the usage of this function and gmttime[_r]() probably by adding our own wrappers. * harbour/source/rtl/hbffind.c ! disabled calls to tzset() - this function should be executed automatically by CRTL only if it's necessary. It's also not MT safe and can cause MT applications crash. --- harbour/ChangeLog | 20 ++++++++++++++++++++ harbour/bin/hbmk.bat | 4 ++++ harbour/source/common/hbdate.c | 4 ++-- harbour/source/compiler/cmdcheck.c | 8 ++++---- harbour/source/rtl/filesys.c | 12 ++++++++---- harbour/source/rtl/hbffind.c | 26 +++++++++++++++----------- 6 files changed, 53 insertions(+), 21 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index d3fc808e9b..c826421638 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,26 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-22 17:45 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/bin/hbmk.bat + * simple modification to make beginning hbmk parameters (-mt and -gui) + position independent though they still have to be used before Harbour/ + C compiler switches and filenames + + * harbour/source/common/hbdate.c + * harbour/source/compiler/cmdcheck.c + * harbour/source/rtl/filesys.c + * harbour/source/rtl/hbffind.c + ! use MT safe localtime_r() function if it's available instead of + localtime() + TODO: clean the usage of this function and gmttime[_r]() probably + by adding our own wrappers. + + * harbour/source/rtl/hbffind.c + ! disabled calls to tzset() - this function should be executed + automatically by CRTL only if it's necessary. It's also not MT + safe and can cause MT applications crash. + 2008-10-22 17:07 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * bin/hbmk.bat * Minor. diff --git a/harbour/bin/hbmk.bat b/harbour/bin/hbmk.bat index 61d7fa32e0..1756119fc9 100644 --- a/harbour/bin/hbmk.bat +++ b/harbour/bin/hbmk.bat @@ -31,16 +31,20 @@ if "%HB_INC_INSTALL%" == "" set HB_INC_INSTALL=%HB_INSTALL_PREFIX%\include set _HB_USR_C= set _HB_USR_L= +:REPEAT + set _HB_MT=%HB_MT% if not "%1" == "-mt" goto NO_MT set _HB_MT=yes shift + goto REPEAT :NO_MT set _HB_GUI=%HB_GUI% if not "%1" == "-gui" goto NO_GUI set _HB_GUI=yes shift + goto REPEAT :NO_GUI set _HBVM_LIB=hbvm diff --git a/harbour/source/common/hbdate.c b/harbour/source/common/hbdate.c index 5adacc4f8e..39c43a8cfb 100644 --- a/harbour/source/common/hbdate.c +++ b/harbour/source/common/hbdate.c @@ -268,7 +268,7 @@ HB_EXPORT void hb_dateToday( int * piYear, int * piMonth, int * piDay ) *piMonth = st.wMonth; *piDay = st.wDay; -#elif defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) +#elif defined( HB_OS_UNIX ) && _POSIX_C_SOURCE >= 199506L && !defined( HB_OS_DARWIN_5 ) time_t t; struct tm st; @@ -305,7 +305,7 @@ HB_EXPORT void hb_dateTimeStr( char * pszTime ) GetLocalTime( &st ); snprintf( pszTime, 9, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond ); } -#elif defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) +#elif defined( HB_OS_UNIX ) && _POSIX_C_SOURCE >= 199506L && !defined( HB_OS_DARWIN_5 ) { time_t t; struct tm st; diff --git a/harbour/source/compiler/cmdcheck.c b/harbour/source/compiler/cmdcheck.c index 6182ac0902..12d8ad4a46 100644 --- a/harbour/source/compiler/cmdcheck.c +++ b/harbour/source/compiler/cmdcheck.c @@ -105,14 +105,14 @@ static ULONG PackDateTime( void ) time_t t; struct tm *oTime; -#if defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) +#if !defined( HB_OS_UNIX ) || _POSIX_C_SOURCE < 199506L || defined( HB_OS_DARWIN_5 ) + time( &t ); + oTime = localtime( &t ); +#else struct tm tm; time( &t ); oTime = &tm; localtime_r( &t, oTime ); -#else - time( &t ); - oTime = localtime( &t ); #endif nValue = ( BYTE ) ( ( ( oTime->tm_year + 1900 ) - 1980 ) & ( 2 ^ 6 ) ); /* 6 bits */ diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index e4b3ae61ff..60aba63414 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -973,13 +973,17 @@ HB_EXPORT BOOL hb_fsGetFileTime( BYTE * pszFileName, LONG * plJulian, LONG * plM if( stat( ( char * ) pszFileName, &sStat ) == 0 ) { time_t ftime; - struct tm * ft; + struct tm ft; ftime = sStat.st_mtime; - ft = localtime( &ftime ); +# if _POSIX_C_SOURCE < 199506L || defined( HB_OS_DARWIN_5 ) + ft = *localtime( &ftime ); +# else + localtime_r( &ftime, &ft ); +# endif - *plJulian = hb_dateEncode( ft->tm_year + 1900, ft->tm_mon + 1, ft->tm_mday ); - *plMillisec = hb_timeStampEncode( ft->tm_hour, ft->tm_min, ft->tm_sec, 0 ); + *plJulian = hb_dateEncode( ft.tm_year + 1900, ft.tm_mon + 1, ft.tm_mday ); + *plMillisec = hb_timeStampEncode( ft.tm_hour, ft.tm_min, ft.tm_sec, 0 ); fResult = TRUE; } diff --git a/harbour/source/rtl/hbffind.c b/harbour/source/rtl/hbffind.c index b7625ce3fe..237d2fb494 100644 --- a/harbour/source/rtl/hbffind.c +++ b/harbour/source/rtl/hbffind.c @@ -448,7 +448,7 @@ static BOOL hb_fsFindNextLow( PHB_FFIND ffind ) { ffind->bFirst = FALSE; - tzset(); + /* tzset(); */ #if defined(__WATCOMC__) bFound = ( _dos_findfirst( ffind->pszFileMask, ( USHORT ) hb_fsAttrToRaw( ffind->attrmask ), &info->entry ) == 0 ); @@ -507,7 +507,7 @@ static BOOL hb_fsFindNextLow( PHB_FFIND ffind ) { ffind->bFirst = FALSE; - tzset(); + /* tzset(); */ info->hFindFile = HDIR_CREATE; info->findCount = 1; @@ -685,7 +685,7 @@ static BOOL hb_fsFindNextLow( PHB_FFIND ffind ) dirname[ 2 ] = '\0'; } - tzset(); + /* tzset(); */ info->dir = opendir( dirname ); hb_strncpy( info->path, dirname, sizeof( info->path ) - 1 ); @@ -711,7 +711,7 @@ static BOOL hb_fsFindNextLow( PHB_FFIND ffind ) hb_strncat( dirname, info->entry->d_name, sizeof( dirname ) - 1 ); { time_t ftime; - struct tm * ft; + struct tm lt; #if defined( HB_USE_LARGEFILE64 ) struct stat64 sStat; if( stat64( dirname, &sStat ) == 0 ) @@ -726,15 +726,19 @@ static BOOL hb_fsFindNextLow( PHB_FFIND ffind ) raw_attr = sStat.st_mode; ftime = sStat.st_mtime; - ft = localtime( &ftime ); +# if _POSIX_C_SOURCE < 199506L || defined( HB_OS_DARWIN_5 ) + lt = *localtime( &ftime ); +# else + localtime_r( &ftime, < ); +# endif - nYear = ft->tm_year + 1900; - nMonth = ft->tm_mon + 1; - nDay = ft->tm_mday; + nYear = lt.tm_year + 1900; + nMonth = lt.tm_mon + 1; + nDay = lt.tm_mday; - nHour = ft->tm_hour; - nMin = ft->tm_min; - nSec = ft->tm_sec; + nHour = lt.tm_hour; + nMin = lt.tm_min; + nSec = lt.tm_sec; } else bFound = FALSE;