From 8759576540ecdc83047ce4aab5d0c5a9cdec500a Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 8 Sep 2006 12:49:43 +0000 Subject: [PATCH] Add HAVE_GMTIME_R and HAVE_LOCALTIME_R flags and use them if defined. Unable to modify the configure script to test for gmtime_r and localtime_r, however, because on my SuSE 10.2 system, autoconf generates a configure script that does not work. Bummer. Ticket #1906 (CVS 3397) FossilOrigin-Name: 862302eaae7bdad6f1b6431f08439c4ce7e0e4bb --- manifest | 12 +++++------ manifest.uuid | 2 +- src/date.c | 55 ++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index 431b85fd3d..712e8f38b5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bug\sfix\sin\sdate/time\scomputations.\s\sTicket\s#1964.\r\nSome\sunrelated\scomment\stypos\sare\salso\sfixed\sand\sgot\saccidently\r\nchecked\sin\sat\sthe\ssame\stime.\s(CVS\s3396) -D 2006-09-08T12:27:37 +C Add\sHAVE_GMTIME_R\sand\sHAVE_LOCALTIME_R\sflags\sand\suse\sthem\sif\sdefined.\nUnable\sto\smodify\sthe\sconfigure\sscript\sto\stest\sfor\sgmtime_r\sand\nlocaltime_r,\showever,\sbecause\son\smy\sSuSE\s10.2\ssystem,\sautoconf\sgenerates\na\sconfigure\sscript\sthat\sdoes\snot\swork.\s\sBummer.\s\sTicket\s#1906\s(CVS\s3397) +D 2006-09-08T12:49:44 F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -53,7 +53,7 @@ F src/btree.h 061c50e37de7f50b58528e352d400cf33ead7418 F src/build.c 4359b34a36938716ed10ac037eec9dc5173b8f4b F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 -F src/date.c bbfc2db2b713193f08bc482c27961a801fce6671 +F src/date.c d5519023569adf30892ff7be6deadf25ecdf1ecd F src/delete.c 804384761144fe1a5035b99f4bd7d706976831bd F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b F src/expr.c 0546cc60f08c426d96092dea0789d085aed3580e @@ -396,7 +396,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 508248e783dc1e3da3695b28467ca3b79629e582 -R db789daf8e27e8308536c276b6e1da10 +P c81eaa0dc9a327d222e066076c4a2da5e69d8c21 +R 6a9c50d36dc1896e63c9a41784e343ad U drh -Z c96944e52a68f5437f07b5ef49e8020c +Z 6afb2ccd411e0e0ff1288b2aea9c08c4 diff --git a/manifest.uuid b/manifest.uuid index af8ed8de63..4add12663b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c81eaa0dc9a327d222e066076c4a2da5e69d8c21 \ No newline at end of file +862302eaae7bdad6f1b6431f08439c4ce7e0e4bb \ No newline at end of file diff --git a/src/date.c b/src/date.c index 1af6fa43fe..80187fa0a4 100644 --- a/src/date.c +++ b/src/date.c @@ -16,7 +16,7 @@ ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.55 2006/09/08 12:27:37 drh Exp $ +** $Id: date.c,v 1.56 2006/09/08 12:49:44 drh Exp $ ** ** NOTES: ** @@ -394,7 +394,6 @@ static void clearYMD_HMS_TZ(DateTime *p){ static double localtimeOffset(DateTime *p){ DateTime x, y; time_t t; - struct tm *pTm; x = *p; computeYMD_HMS(&x); if( x.Y<1971 || x.Y>=2038 ){ @@ -412,15 +411,31 @@ static double localtimeOffset(DateTime *p){ x.validJD = 0; computeJD(&x); t = (x.rJD-2440587.5)*86400.0 + 0.5; - sqlite3OsEnterMutex(); - pTm = localtime(&t); - y.Y = pTm->tm_year + 1900; - y.M = pTm->tm_mon + 1; - y.D = pTm->tm_mday; - y.h = pTm->tm_hour; - y.m = pTm->tm_min; - y.s = pTm->tm_sec; - sqlite3OsLeaveMutex(); +#ifdef HAVE_LOCALTIME_R + { + struct tm sLocal; + localtime_r(&t, &sLocal); + y.Y = sLocal.tm_year + 1900; + y.M = sLocal.tm_mon + 1; + y.D = sLocal.tm_mday; + y.h = sLocal.tm_hour; + y.m = sLocal.tm_min; + y.s = sLocal.tm_sec; + } +#else + { + struct tm *pTm; + sqlite3OsEnterMutex(); + pTm = localtime(&t); + y.Y = pTm->tm_year + 1900; + y.M = pTm->tm_mon + 1; + y.D = pTm->tm_mday; + y.h = pTm->tm_hour; + y.m = pTm->tm_min; + y.s = pTm->tm_sec; + sqlite3OsLeaveMutex(); + } +#endif y.validYMD = 1; y.validHMS = 1; y.validJD = 0; @@ -945,9 +960,21 @@ static void currentTimeFunc( } #endif - sqlite3OsEnterMutex(); - strftime(zBuf, 20, zFormat, gmtime(&t)); - sqlite3OsLeaveMutex(); +#ifdef HAVE_GMTIME_R + { + struct tm sNow; + gmtime_r(&t, &sNow); + strftime(zBuf, 20, zFormat, &sNow); + } +#else + { + struct tm *pTm; + sqlite3OsEnterMutex(); + pTm = gmtime(&t); + strftime(zBuf, 20, zFormat, pTm); + sqlite3OsLeaveMutex(); + } +#endif sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); }