From d44fea92a9c8f019becf8c0bbb7bca6e8a8bb91d Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 11 Mar 2009 16:39:32 +0000 Subject: [PATCH] 2009-03-11 17:45 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbdate.h * harbour/source/common/hbgete.c * harbour/source/common/hbdate.c * harbour/source/rtl/seconds.c * harbour/source/rtl/hbffind.c * harbour/source/rtl/filesys.c * harbour/source/compiler/cmdcheck.c * harbour/contrib/hbct/files.c * harbour/contrib/xhb/filestat.c * harbour/contrib/hbmzip/hbmzip.c * harbour/contrib/hbtip/utils.c * harbour/contrib/examples/uhttpd/uhttpdc.c * cleaned feature test macros usage --- harbour/ChangeLog | 15 +++++ harbour/contrib/examples/uhttpd/uhttpdc.c | 18 +++--- harbour/contrib/hbct/files.c | 4 +- harbour/contrib/hbmzip/hbmzip.c | 16 ++--- harbour/contrib/hbtip/utils.c | 7 +-- harbour/contrib/xhb/filestat.c | 4 +- harbour/include/hbdate.h | 8 +++ harbour/source/common/hbdate.c | 72 +++++++++-------------- harbour/source/common/hbgete.c | 2 +- harbour/source/compiler/cmdcheck.c | 4 +- harbour/source/rtl/filesys.c | 24 +++----- harbour/source/rtl/hbffind.c | 8 +-- harbour/source/rtl/seconds.c | 16 ++--- 13 files changed, 91 insertions(+), 107 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index bbb82abb57..81dd1ef23c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,21 @@ 2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2009-03-11 17:45 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbdate.h + * harbour/source/common/hbgete.c + * harbour/source/common/hbdate.c + * harbour/source/rtl/seconds.c + * harbour/source/rtl/hbffind.c + * harbour/source/rtl/filesys.c + * harbour/source/compiler/cmdcheck.c + * harbour/contrib/hbct/files.c + * harbour/contrib/xhb/filestat.c + * harbour/contrib/hbmzip/hbmzip.c + * harbour/contrib/hbtip/utils.c + * harbour/contrib/examples/uhttpd/uhttpdc.c + * cleaned feature test macros usage + 2009-03-11 16:27 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/common/hbdate.c * harbour/source/compiler/cmdcheck.c diff --git a/harbour/contrib/examples/uhttpd/uhttpdc.c b/harbour/contrib/examples/uhttpd/uhttpdc.c index e17aa20048..94143827dd 100644 --- a/harbour/contrib/examples/uhttpd/uhttpdc.c +++ b/harbour/contrib/examples/uhttpd/uhttpdc.c @@ -60,6 +60,7 @@ #define HB_OS_WIN_USED #include "hbapi.h" +#include "hbdate.h" #if !defined( HB_OS_WIN ) #include @@ -154,22 +155,17 @@ HB_FUNC( HB_UTCOFFSET ) nLen = strlen( szRet ); } -#elif defined( HB_OS_UNIX ) && _POSIX_C_SOURCE >= 199506L && !defined( HB_OS_DARWIN_5 ) - { - struct tm tmTime; - time_t current; - - time( ¤t ); - localtime_r( ¤t , &tmTime ); - - nLen = strftime( szRet, 6, "%z", &tmTime ); - } #else { struct tm tmTime; time_t current; - memcpy( ( void * ) &tmTime, ( void * ) localtime( ¤t ), sizeof( tmTime ) ); + time( ¤t ); +# if defined( HB_HAS_LOCALTIME_R ) + localtime_r( ¤t, &tmTime ); +# else + tmTime = *localtime( ¤t ); +# endif nLen = strftime( szRet, 6, "%z", &tmTime ); } #endif diff --git a/harbour/contrib/hbct/files.c b/harbour/contrib/hbct/files.c index 9db057cd77..af64441025 100644 --- a/harbour/contrib/hbct/files.c +++ b/harbour/contrib/hbct/files.c @@ -331,9 +331,7 @@ HB_FUNC( SETFDATI ) time_t current_time; current_time = time( NULL ); -#if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) +#if defined( HB_HAS_LOCALTIME_R ) localtime_r( ¤t_time, &new_value ); # else new_value = *localtime( ¤t_time ); diff --git a/harbour/contrib/hbmzip/hbmzip.c b/harbour/contrib/hbmzip/hbmzip.c index 3cd531fb75..f8cd8ff2eb 100644 --- a/harbour/contrib/hbmzip/hbmzip.c +++ b/harbour/contrib/hbmzip/hbmzip.c @@ -755,11 +755,11 @@ static int hb_zipStoreFile( zipFile hZip, const char* szFileName, const char* sz ( ( statbuf.st_mode & S_IWUSR ) ? 0x00800000 : 0 ) | ( ( statbuf.st_mode & S_IRUSR ) ? 0x01000000 : 0 ); -# if _POSIX_C_SOURCE < 199506L || defined( HB_OS_DARWIN_5 ) - st = *localtime( &statbuf.st_mtime ); -# else +# if defined( HB_HAS_LOCALTIME_R ) localtime_r( &statbuf.st_mtime, &st ); -# endif +# else + st = *localtime( &statbuf.st_mtime ); +# endif zfi.tmz_date.tm_sec = st.tm_sec; zfi.tmz_date.tm_min = st.tm_min; @@ -1144,11 +1144,11 @@ static int hb_unzipExtractCurrentFile( unzFile hUnzip, const char* szFileName, c st.tm_year = ufi.tmu_date.tm_year - 1900; tim = mktime( &st ); -# if _POSIX_C_SOURCE < 199506L || defined( HB_OS_DARWIN_5 ) - st = *gmtime( &tim ); -# else +# if defined( HB_HAS_LOCALTIME_R ) gmtime_r( &tim, &st ); -# endif +# else + st = *gmtime( &tim ); +# endif utim.actime = utim.modtime = mktime( &st ); utime( szName, &utim ); diff --git a/harbour/contrib/hbtip/utils.c b/harbour/contrib/hbtip/utils.c index 28a9629276..006ca1e49b 100644 --- a/harbour/contrib/hbtip/utils.c +++ b/harbour/contrib/hbtip/utils.c @@ -171,13 +171,12 @@ HB_FUNC( TIP_TIMESTAMP ) ulHour = 0; } - /* init time structure anyway */ time( ¤t ); -#if _POSIX_C_SOURCE < 199506L || defined( HB_OS_DARWIN_5 ) - memcpy( (void *) &tmTime, (void *) localtime( ¤t ), sizeof(tmTime) ); -#else +#if defined( HB_HAS_LOCALTIME_R ) localtime_r( ¤t , &tmTime ); +#else + tmTime = *localtime( ¤t ); #endif if ( pDate ) diff --git a/harbour/contrib/xhb/filestat.c b/harbour/contrib/xhb/filestat.c index 84e56b53cd..f449db6be8 100644 --- a/harbour/contrib/xhb/filestat.c +++ b/harbour/contrib/xhb/filestat.c @@ -153,7 +153,7 @@ static BOOL hb_fsFileStats( *llSize = ( HB_FOFFSET ) statbuf.st_size; ftime = statbuf.st_mtime; -#if _POSIX_C_SOURCE >= 199506L && !defined( HB_OS_DARWIN_5 ) +#if defined( HB_HAS_LOCALTIME_R ) ptms = localtime_r( &ftime, &tms ); #else ptms = localtime( &ftime ); @@ -164,7 +164,7 @@ static BOOL hb_fsFileStats( *lcTime = ptms->tm_hour*3600 + ptms->tm_min * 60 + ptms->tm_sec; ftime = statbuf.st_atime; -#if _POSIX_C_SOURCE >= 199506L && !defined( HB_OS_DARWIN_5 ) +#if defined( HB_HAS_LOCALTIME_R ) ptms = localtime_r( &ftime, &tms ); #else ptms = localtime( &ftime ); diff --git a/harbour/include/hbdate.h b/harbour/include/hbdate.h index 971157dd85..f2a52140f3 100644 --- a/harbour/include/hbdate.h +++ b/harbour/include/hbdate.h @@ -82,6 +82,14 @@ extern HB_EXPORT void hb_dateStrGet( const char * szDate, int * piYear, int * extern HB_EXPORT char * hb_dateDecStr( char * szDate, long lJulian ); extern HB_EXPORT long hb_dateEncStr( const char * szDate ); +#if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ + defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) || \ + defined( HB_OS_SUNOS ) ) && \ + ! defined( HB_OS_DARWIN_5 ) && !defined( HB_HAS_LOCALTIME_R ) +# define HB_HAS_LOCALTIME_R +#endif + + HB_EXTERN_END #endif /* HB_DATE_H_ */ diff --git a/harbour/source/common/hbdate.c b/harbour/source/common/hbdate.c index 91a7242a90..144db73158 100644 --- a/harbour/source/common/hbdate.c +++ b/harbour/source/common/hbdate.c @@ -260,40 +260,31 @@ int hb_dateDOW( int iYear, int iMonth, int iDay ) void hb_dateToday( int * piYear, int * piMonth, int * piDay ) { #if defined(HB_OS_WIN) + { + SYSTEMTIME st; - SYSTEMTIME st; - GetLocalTime( &st ); - - *piYear = st.wYear; - *piMonth = st.wMonth; - *piDay = st.wDay; - -#elif ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) - - time_t t; - struct tm st; - - time( &t ); - localtime_r( &t, &st ); - - *piYear = st.tm_year + 1900; - *piMonth = st.tm_mon + 1; - *piDay = st.tm_mday; + GetLocalTime( &st ); + *piYear = st.wYear; + *piMonth = st.wMonth; + *piDay = st.wDay; + } #else + { + time_t t; + struct tm st; - time_t t; - struct tm * oTime; - - time( &t ); - oTime = localtime( &t ); - - *piYear = oTime->tm_year + 1900; - *piMonth = oTime->tm_mon + 1; - *piDay = oTime->tm_mday; + time( &t ); +# if defined( HB_HAS_LOCALTIME_R ) + localtime_r( &t, &st ); +# else + st = *localtime( &t ); +# endif + *piYear = st.tm_year + 1900; + *piMonth = st.tm_mon + 1; + *piDay = st.tm_mday; + } #endif } @@ -307,26 +298,17 @@ void hb_dateTimeStr( char * pszTime ) GetLocalTime( &st ); hb_snprintf( pszTime, 9, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond ); } -#elif ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) - { - time_t t; - struct tm st; - - time( &t ); - localtime_r( &t, &st ); - - hb_snprintf( pszTime, 9, "%02d:%02d:%02d", st.tm_hour, st.tm_min, st.tm_sec ); - } #else { time_t t; - struct tm * oTime; - + struct tm st; time( &t ); - oTime = localtime( &t ); - hb_snprintf( pszTime, 9, "%02d:%02d:%02d", oTime->tm_hour, oTime->tm_min, oTime->tm_sec ); +# if defined( HB_HAS_LOCALTIME_R ) + localtime_r( &t, &st ); +# else + st = *localtime( &t ); +# endif + hb_snprintf( pszTime, 9, "%02d:%02d:%02d", st.tm_hour, st.tm_min, st.tm_sec ); } #endif } diff --git a/harbour/source/common/hbgete.c b/harbour/source/common/hbgete.c index db0bf13042..b9df75d6af 100644 --- a/harbour/source/common/hbgete.c +++ b/harbour/source/common/hbgete.c @@ -158,7 +158,7 @@ BOOL hb_setenv( const char * szName, const char * szValue ) #elif defined( _BSD_SOURCE ) || _POSIX_C_SOURCE >= 200112L || \ _XOPEN_SOURCE >= 600 || defined( __WATCOMC__ ) || defined( __DJGPP__ ) || \ - defined( HB_OS_BSD ) || defined( HB_OS_DARWIN ) + defined( HB_OS_SUNOS ) || defined( HB_OS_BSD ) || defined( HB_OS_DARWIN ) if( szValue ) return setenv( szName, szValue, 1 ) == 0; diff --git a/harbour/source/compiler/cmdcheck.c b/harbour/source/compiler/cmdcheck.c index e217410550..a0e1eccb79 100644 --- a/harbour/source/compiler/cmdcheck.c +++ b/harbour/source/compiler/cmdcheck.c @@ -106,9 +106,7 @@ static ULONG PackDateTime( void ) struct tm tm; time( &t ); -#if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) +#if defined( HB_HAS_LOCALTIME_R ) localtime_r( &t, &tm ); #else tm = *localtime( &t ); diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index 037c11db69..e289474c95 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -964,13 +964,11 @@ BOOL hb_fsGetFileTime( BYTE * pszFileName, LONG * plJulian, LONG * plMillisec ) struct tm ft; ftime = sStat.st_mtime; -# if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) +# if defined( HB_HAS_LOCALTIME_R ) localtime_r( &ftime, &ft ); -# else +# else ft = *localtime( &ftime ); -# endif +# 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 ); @@ -1204,13 +1202,11 @@ BOOL hb_fsSetFileTime( BYTE * pszFileName, LONG lJulian, LONG lMillisec ) time_t current_time; current_time = time( NULL ); -# if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) +# if defined( HB_HAS_LOCALTIME_R ) localtime_r( ¤t_time, &new_value ); -# else +# else new_value = *localtime( ¤t_time ); -# endif +# endif } else memset( &new_value, 0, sizeof( new_value ) ); @@ -1228,13 +1224,11 @@ BOOL hb_fsSetFileTime( BYTE * pszFileName, LONG lJulian, LONG lMillisec ) new_value.tm_sec = iSecond; } tim = mktime( &new_value ); -# if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) +# if defined( HB_HAS_LOCALTIME_R ) gmtime_r( &tim, &new_value ); -# else +# else new_value = *gmtime( &tim ); -# endif +# endif buf.actime = buf.modtime = mktime( &new_value ); fResult = utime( ( char * ) pszFileName, &buf ) == 0; } diff --git a/harbour/source/rtl/hbffind.c b/harbour/source/rtl/hbffind.c index 6c9a73f305..322a3905e1 100644 --- a/harbour/source/rtl/hbffind.c +++ b/harbour/source/rtl/hbffind.c @@ -709,13 +709,11 @@ static BOOL hb_fsFindNextLow( PHB_FFIND ffind ) raw_attr = sStat.st_mode; ftime = sStat.st_mtime; -# if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) +# if defined( HB_HAS_LOCALTIME_R ) localtime_r( &ftime, < ); -# else +# else lt = *localtime( &ftime ); -# endif +# endif nYear = lt.tm_year + 1900; nMonth = lt.tm_mon + 1; diff --git a/harbour/source/rtl/seconds.c b/harbour/source/rtl/seconds.c index 79349a2c19..6348b0213c 100644 --- a/harbour/source/rtl/seconds.c +++ b/harbour/source/rtl/seconds.c @@ -114,13 +114,11 @@ void hb_dateTimeStamp( LONG * plJulian, LONG * plMilliSec ) millisecs = tb.millitm; # endif -#if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) +# if defined( HB_HAS_LOCALTIME_R ) localtime_r( &seconds, &st ); -#else +# else st = *localtime( &seconds ); -#endif +# endif *plJulian = hb_dateEncode( st.tm_year + 1900, st.tm_mon + 1, st.tm_mday ); *plMilliSec = ( ( st.tm_hour * 60 + st.tm_min ) * 60 + st.tm_sec ) * 1000 + millisecs; @@ -185,13 +183,11 @@ double hb_dateSeconds( void ) msecs = ( double ) tb.millitm / 1000.0; # endif -#if ( defined( _POSIX_C_SOURCE ) || defined( _XOPEN_SOURCE ) || \ - defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) ) && \ - ! defined( HB_OS_DARWIN_5 ) +# if defined( HB_HAS_LOCALTIME_R ) localtime_r( &seconds, &oTime ); -#else +# else oTime = *localtime( &seconds ); -#endif +# endif return ( oTime.tm_hour * 3600 ) + ( oTime.tm_min * 60 ) + oTime.tm_sec + msecs;