]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add HAVE_GMTIME_R and HAVE_LOCALTIME_R flags and use them if defined.
authordrh <drh@noemail.net>
Fri, 8 Sep 2006 12:49:43 +0000 (12:49 +0000)
committerdrh <drh@noemail.net>
Fri, 8 Sep 2006 12:49:43 +0000 (12:49 +0000)
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
manifest.uuid
src/date.c

index 431b85fd3df8ce2fb6c7f316c303a54735b0cb08..712e8f38b548df5737452ca9ed66b630c7f00a9d 100644 (file)
--- 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
index af8ed8de63971873af4fe2aafda9e9e2d297141d..4add12663b8028939cfeb72e5697e0e65b951ee7 100644 (file)
@@ -1 +1 @@
-c81eaa0dc9a327d222e066076c4a2da5e69d8c21
\ No newline at end of file
+862302eaae7bdad6f1b6431f08439c4ce7e0e4bb
\ No newline at end of file
index 1af6fa43fe2215edb9447bf56732124cc30dfa03..80187fa0a4a335a996d4d40e3b6245fec3a953de 100644 (file)
@@ -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);
 }