@@ -96,7 +96,7 @@ static sqlcipher_provider *default_provider = NULL;
9696static sqlite3_mutex * sqlcipher_static_mutex [SQLCIPHER_MUTEX_COUNT ];
9797static volatile FILE * sqlcipher_log_file = NULL ;
9898static volatile int sqlcipher_log_logcat = 0 ;
99- static volatile int sqlcipher_log_level = SQLCIPHER_LOG_NONE ;
99+ static volatile unsigned int sqlcipher_log_level = SQLCIPHER_LOG_NONE ;
100100
101101sqlite3_mutex * sqlcipher_mutex (int mutex ) {
102102 if (mutex < 0 || mutex >= SQLCIPHER_MUTEX_COUNT ) return NULL ;
@@ -1706,6 +1706,9 @@ const char* sqlcipher_codec_get_provider_version(codec_ctx *ctx) {
17061706}
17071707
17081708#ifndef SQLCIPHER_OMIT_LOG
1709+ /* constants from https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-crt/misc/gettimeofday.c */
1710+ #define FILETIME_1970 116444736000000000ull /* seconds between 1/1/1601 and 1/1/1970 */
1711+ #define HECTONANOSEC_PER_SEC 10000000ull
17091712void sqlcipher_log (unsigned int level , const char * message , ...) {
17101713 va_list params ;
17111714 va_start (params , message );
@@ -1724,14 +1727,27 @@ void sqlcipher_log(unsigned int level, const char *message, ...) {
17241727 goto end ;
17251728 }
17261729 if (sqlcipher_log_file != NULL ){
1727- char buffer [20 ];
1730+ char buffer [256 ];
17281731 struct tm tt ;
1729- struct timeval tv ;
17301732 int ms ;
1733+ time_t sec ;
1734+ #ifdef _WIN32
1735+ SYSTEMTIME st ;
1736+ FILETIME ft ;
1737+ GetSystemTime (& st );
1738+ SystemTimeToFileTime (& st , & ft );
1739+ sec = (time_t ) ((* ((sqlite_int64 * )& ft ) - FILETIME_1970 ) / HECTONANOSEC_PER_SEC );
1740+ ms = st .wMilliseconds ;
1741+ localtime_s (& tt , & sec );
1742+ #else
1743+ struct timeval tv ;
17311744 gettimeofday (& tv , NULL );
1745+ sec = tv .tv_sec ;
17321746 ms = tv .tv_usec /1000.0 ;
1733- localtime_r (& tv .tv_sec , & tt );
1734- strftime (buffer , 20 , "%Y-%m-%d %H:%M:%S" , & tt );
1747+ localtime_r (& sec , & tt );
1748+ #endif
1749+ sqlcipher_memset (buffer , 0 , 256 );
1750+ strftime (buffer , sizeof (buffer ), "%Y-%m-%d %H:%M:%S" , & tt );
17351751 fprintf ((FILE * )sqlcipher_log_file , "%s.%03d: " , buffer , ms );
17361752 vfprintf ((FILE * )sqlcipher_log_file , message , params );
17371753 fprintf ((FILE * )sqlcipher_log_file , "\n" );
@@ -1746,7 +1762,7 @@ void sqlcipher_log(unsigned int level, const char *message, ...) {
17461762}
17471763#endif
17481764
1749- int sqlcipher_set_log_level (unsigned int level ) {
1765+ void sqlcipher_set_log_level (unsigned int level ) {
17501766 sqlcipher_log_level = level ;
17511767}
17521768
0 commit comments