mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Use VFS method xCurrentTimeInt64 instead of xCurrentTime when it is available.
Provide an implementation of xCurrentTimeInt64 for os_unix.c. FossilOrigin-Name: ab77b3ae6da3370d8bc3b2c9c0edc723b69f5a95
This commit is contained in:
@@ -4515,36 +4515,49 @@ static int unixSleep(sqlite3_vfs *NotUsed, int microseconds){
|
||||
int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
|
||||
#endif
|
||||
|
||||
/*
|
||||
** 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 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);
|
||||
*piNow = ((sqlite3_int64)i)*1000 + unixEpoch;
|
||||
#elif OS_VXWORKS
|
||||
struct timespec sNow;
|
||||
clock_gettime(CLOCK_REALTIME, &sNow);
|
||||
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
|
||||
#else
|
||||
struct timeval sNow;
|
||||
gettimeofday(&sNow, 0);
|
||||
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
if( sqlite3_current_time ){
|
||||
*piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
|
||||
}
|
||||
#endif
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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){
|
||||
#if defined(SQLITE_OMIT_FLOATING_POINT)
|
||||
time_t t;
|
||||
time(&t);
|
||||
*prNow = (((sqlite3_int64)t)/8640 + 24405875)/10;
|
||||
#elif defined(NO_GETTOD)
|
||||
time_t t;
|
||||
time(&t);
|
||||
*prNow = t/86400.0 + 2440587.5;
|
||||
#elif OS_VXWORKS
|
||||
struct timespec sNow;
|
||||
clock_gettime(CLOCK_REALTIME, &sNow);
|
||||
*prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_nsec/86400000000000.0;
|
||||
#else
|
||||
struct timeval sNow;
|
||||
gettimeofday(&sNow, 0);
|
||||
*prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0;
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
if( sqlite3_current_time ){
|
||||
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
|
||||
}
|
||||
#endif
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
sqlite3_int64 i;
|
||||
unixCurrentTimeInt64(0, &i);
|
||||
*prNow = i*86400000.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6601,7 +6614,7 @@ int sqlite3_os_init(void){
|
||||
unixShmLock, /* xShmLock */ \
|
||||
unixShmClose, /* xShmClose */ \
|
||||
0, /* xRename */ \
|
||||
0, /* xCurrentTimeInt64 */ \
|
||||
unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user