diff options
author | drh <drh@noemail.net> | 2010-05-03 14:32:30 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2010-05-03 14:32:30 +0000 |
commit | b7e8ea201518d52b01ac7b5b40df7e05fe9dd6be (patch) | |
tree | 74c52d5e58a2453ce51264542adfe2b5b275c1ff /src/os_unix.c | |
parent | e8e1c9d50e2c33685d8377954f80ce871ebbb458 (diff) | |
download | sqlite-b7e8ea201518d52b01ac7b5b40df7e05fe9dd6be.tar.gz sqlite-b7e8ea201518d52b01ac7b5b40df7e05fe9dd6be.zip |
Use VFS method xCurrentTimeInt64 instead of xCurrentTime when it is available.
Provide an implementation of xCurrentTimeInt64 for os_unix.c.
FossilOrigin-Name: ab77b3ae6da3370d8bc3b2c9c0edc723b69f5a95
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index 986963a18..cb3e19009 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -4516,32 +4516,33 @@ int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */ #endif /* -** Find the current time (in Universal Coordinated Time). Write the -** current time and date as a Julian Day number into *prNow and -** return 0. Return 1 if the time and date cannot be found. +** Find the current time (in Universal Coordinated Time). Write into *piNow +** the current time and date as a Julian Day number times 86_400_000. In +** other words, write into *piNow the number of milliseconds since the Julian +** epoch of noon in Greenwich on November 24, 4714 B.C according to the +** proleptic Gregorian calendar. +** +** On success, return 0. Return 1 if the time and date cannot be found. */ -static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){ -#if defined(SQLITE_OMIT_FLOATING_POINT) - time_t t; - time(&t); - *prNow = (((sqlite3_int64)t)/8640 + 24405875)/10; -#elif defined(NO_GETTOD) +static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){ + static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000; +#if defined(NO_GETTOD) time_t t; time(&t); - *prNow = t/86400.0 + 2440587.5; + *piNow = ((sqlite3_int64)i)*1000 + unixEpoch; #elif OS_VXWORKS struct timespec sNow; clock_gettime(CLOCK_REALTIME, &sNow); - *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_nsec/86400000000000.0; + *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000; #else struct timeval sNow; gettimeofday(&sNow, 0); - *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0; + *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; #endif #ifdef SQLITE_TEST if( sqlite3_current_time ){ - *prNow = sqlite3_current_time/86400.0 + 2440587.5; + *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch; } #endif UNUSED_PARAMETER(NotUsed); @@ -4549,6 +4550,18 @@ static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){ } /* +** Find the current time (in Universal Coordinated Time). Write the +** current time and date as a Julian Day number into *prNow and +** return 0. Return 1 if the time and date cannot be found. +*/ +static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){ + sqlite3_int64 i; + unixCurrentTimeInt64(0, &i); + *prNow = i*86400000.0; + return 0; +} + +/* ** We added the xGetLastError() method with the intention of providing ** better low-level error messages when operating-system problems come up ** during SQLite operation. But so far, none of that has been implemented @@ -6601,7 +6614,7 @@ int sqlite3_os_init(void){ unixShmLock, /* xShmLock */ \ unixShmClose, /* xShmClose */ \ 0, /* xRename */ \ - 0, /* xCurrentTimeInt64 */ \ + unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \ } /* |