1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

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
This commit is contained in:
drh
2006-09-08 12:49:43 +00:00
parent f11c34df74
commit 8759576540
3 changed files with 48 additions and 21 deletions

View 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);
}