1
0
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:
drh
2007-09-03 13:06:11 +00:00
parent ee6c9722cc
commit d1a793126a
3 changed files with 30 additions and 12 deletions

View File

@@ -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;
}