]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Simplifications to the localtime() interface. Fix the case where
authordrh <drh@noemail.net>
Tue, 21 Jun 2011 14:35:30 +0000 (14:35 +0000)
committerdrh <drh@noemail.net>
Tue, 21 Jun 2011 14:35:30 +0000 (14:35 +0000)
localtime_r() is available so that it works.  Ticket [bd484a090c8077].

FossilOrigin-Name: 5b68dae320d0fa3dc433826811e5018a47461de7

manifest
manifest.uuid
src/date.c

index 3b86500f0fb91f79c472e97abfe05726c1a810f5..c16e50aa1284754b83f411b6dc6e201de03f00bd 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Change\sthe\serror\smessage\sreturned\swhen\slocaltime_r()\sfails\sto\s"local\stime\sunavailable".
-D 2011-06-21T13:46:11.287
+C Simplifications\sto\sthe\slocaltime()\sinterface.\s\sFix\sthe\scase\swhere\nlocaltime_r()\sis\savailable\sso\sthat\sit\sworks.\s\sTicket\s[bd484a090c8077].
+D 2011-06-21T14:35:30.890
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in c1d7a7f4fd8da6b1815032efca950e3d5125407e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -131,7 +131,7 @@ F src/build.c 5a428625d21ad409514afb40ad083bee25dd957a
 F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a
 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
 F src/ctime.c 7deec4534f3b5a0c3b4a4cbadf809d321f64f9c4
-F src/date.c 193172e7a5e46b710bbf0f4211583ff6c23c7e21
+F src/date.c 2c5b336a05029c1647f7a4fe03d7ee50b9747bba
 F src/delete.c cecc926c70783452f3e8eb452c728291ce1a0b21
 F src/expr.c ab46ab0f0c44979a8164ca31728d7d10ae5e8106
 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
@@ -948,7 +948,7 @@ F tool/symbols.sh bc2a3709940d47c8ac8e0a1fdf17ec801f015a00
 F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings.sh 347d974d143cf132f953b565fbc03026f19fcb4d
-P 97e86ec6df4d893527fe9f43eb46163d9b06416a
-R e0015d917e226c6056689f5a9862debe
-U dan
-Z 66bfa4b384ab8dfebefd27a1fbb7cf7e
+P 0e82175fd86f0ca5da90676aaee3118a70264d85
+R 39249556a57f6de5d465bb75e25a77c9
+U drh
+Z f3f5de06e02a4cdc489a3c883165212f
index d35b4bff4d5f1507ba246fbcbd57252a75bbfeb0..11d082e2ed30a0a10767662141053c3919232711 100644 (file)
@@ -1 +1 @@
-0e82175fd86f0ca5da90676aaee3118a70264d85
\ No newline at end of file
+5b68dae320d0fa3dc433826811e5018a47461de7
\ No newline at end of file
index 1cf51183e91f3a4313b90e67ea167d25ff2cb6b4..36503420cd325add2e2f87a4ebdcd772ba1878b5 100644 (file)
@@ -412,41 +412,41 @@ static void clearYMD_HMS_TZ(DateTime *p){
 }
 
 #ifndef SQLITE_OMIT_LOCALTIME
-
 /*
-** The following three functions - osLocaltime_r(), osLocaltime_s() and
-** osLocaltime() - are wrappers around system functions localtime_r(),
-** localtime_s() and localtime(), respectively.
+** The following routine implements the rough equivalent of localtime_r()
+** using whatever operating-system specific localtime facility that
+** is available.  This routine returns 0 on success and
+** non-zero on any kind of error.
 **
-** If the sqlite3GlobalConfig.bLocaltimeFault variable is true when one
-** of the following wrappers is called, it returns an error.
+** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this
+** routine will always fail.
 */
+int osLocaltime(time_t *t, struct tm *pTm){
+  int rc;
 #ifndef SQLITE_OMIT_BUILTIN_TEST
-
-#ifdef HAVE_LOCALTIME_R
-static struct tm * osLocaltime_r(time_t *t, struct tm *pTm){
-  if( sqlite3GlobalConfig.bLocaltimeFault ) return 0;
-  return localtime_r(t);
-}
-#elif defined(HAVE_LOCALTIME_S) && HAVE_LOCALTIME_S
-static int osLocaltime_s(struct tm *pTm, time_t *t){
   if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
-  return (int)localtime_s(pTm, t);
-}
-#else
-static struct tm * osLocaltime(time_t *t){
-  if( sqlite3GlobalConfig.bLocaltimeFault ) return 0;
-  return localtime(t);
-}
 #endif
-
+#ifdef HAVE_LOCALTIME_R
+  rc = localtime_r(t, pTm)==0;
+#elif defined(HAVE_LOCALTIME_S) && HAVE_LOCALTIME_S
+  rc = localtime_s(pTm, t);
 #else
-# define osLocaltime_r(x,y) localtime_r(x,y)
-# define osLocaltime_s(x,y) localtime_s(x,y)
-# define osLocaltime(x)     localtime(x)
+  {
+    struct tm *pX;
+    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
+    sqlite3_mutex_enter(mutex);
+    pX = localtime(t);
+    if( pX ) *pTm = *pX;
+    sqlite3_mutex_leave(mutex);
+    rc = pX==0;
+  }
 #endif
+  return rc;
+}
+#endif /* SQLITE_OMIT_LOCALTIME */
 
 
+#ifndef SQLITE_OMIT_LOCALTIME
 /*
 ** Compute the difference (in milliseconds) between localtime and UTC
 ** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
@@ -462,6 +462,8 @@ static sqlite3_int64 localtimeOffset(
 ){
   DateTime x, y;
   time_t t;
+  struct tm sLocal;
+
   x = *p;
   computeYMD_HMS(&x);
   if( x.Y<1971 || x.Y>=2038 ){
@@ -479,57 +481,17 @@ static sqlite3_int64 localtimeOffset(
   x.validJD = 0;
   computeJD(&x);
   t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
-#ifdef HAVE_LOCALTIME_R
-  {
-    struct tm sLocal;
-    if( 0==osLocaltime_r(&t, &sLocal) ){
-      sqlite3_result_error(pCtx, "local time unavailable", -1);
-      *pRc = SQLITE_ERROR;
-      return 0;
-    }
-    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;
-  }
-#elif defined(HAVE_LOCALTIME_S) && HAVE_LOCALTIME_S
-  {
-    struct tm sLocal;
-    if( 0!=osLocaltime_s(&sLocal, &t) ){
-      sqlite3_result_error(pCtx, "local time unavailable", -1);
-      *pRc = SQLITE_ERROR;
-      return 0;
-    }
-    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;
-    sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
-    pTm = osLocaltime(&t);
-    if( pTm ){
-      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;
-    }
-    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
-    if( !pTm ){
-      sqlite3_result_error(pCtx, "local time unavailable", -1);
-      *pRc = SQLITE_ERROR;
-      return 0;
-    }
+  if( osLocaltime(&t, &sLocal) ){
+    sqlite3_result_error(pCtx, "local time unavailable", -1);
+    *pRc = SQLITE_ERROR;
+    return 0;
   }
-#endif
+  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;
   y.validYMD = 1;
   y.validHMS = 1;
   y.validJD = 0;