mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-15 11:41:13 +03:00
Improvements to the xRandomness() method on the default windows VFS.
Ticket #2615. (CVS 4374) FossilOrigin-Name: 91b50f31e35652a40d51f5d9bf22efce36d515e4
This commit is contained in:
28
src/os_win.c
28
src/os_win.c
@@ -1421,12 +1421,30 @@ void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
|
||||
** Write up to nBuf bytes of randomness into zBuf.
|
||||
*/
|
||||
static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
|
||||
if( sizeof(LPSYSTEMTIME)>=nBuf ){
|
||||
GetSystemTime((LPSYSTEMTIME)zBuf);
|
||||
return sizeof(LPSYSTEMTIME);
|
||||
}else{
|
||||
return 0;
|
||||
int n = 0;
|
||||
if( sizeof(LPSYSTEMTIME)<=nBuf-n ){
|
||||
SYSTEMTIME x;
|
||||
GetSystemTime(&x);
|
||||
memcpy(&zBuf[n], &x, sizeof(x));
|
||||
n += sizeof(x);
|
||||
}
|
||||
if( sizeof(DWORD)<=nBuf-n ){
|
||||
DWORD pid = GetCurrentProcessId();
|
||||
memcpy(&zBuf[n], &pid, sizeof(pid));
|
||||
n += sizeof(pid);
|
||||
}
|
||||
if( sizeof(DWORD)<=nBuf-n ){
|
||||
DWORD cnt = GetTickCount();
|
||||
memcpy(&zBuf[n], &cnt, sizeof(cnt));
|
||||
n += sizeof(cnt);
|
||||
}
|
||||
if( sizeof(LARGE_INTEGER)<=nBuf-n ){
|
||||
LARGE_INTEGER i;
|
||||
QueryPerformanceCounter(&i);
|
||||
memcpy(&zBuf[n], &i, sizeof(i));
|
||||
n += sizeof(i);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user