1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-27 08:52:26 +03:00

Initialize the random number generator from /dev/urandom, if available. (CVS 2258)

FossilOrigin-Name: aab8e7f8d81ffa786d5fae5a13963c6e58a8eefc
This commit is contained in:
drh
2005-01-21 17:53:17 +00:00
parent 0602c2e4a5
commit 842b864118
3 changed files with 17 additions and 11 deletions

View File

@@ -1183,10 +1183,16 @@ int sqlite3OsRandomSeed(char *zBuf){
memset(zBuf, 0, 256);
#if !defined(SQLITE_TEST)
{
int pid;
time((time_t*)zBuf);
pid = getpid();
memcpy(&zBuf[sizeof(time_t)], &pid, sizeof(pid));
int pid, fd;
fd = open("/dev/urandom", O_RDONLY);
if( fd<0 ){
time((time_t*)zBuf);
pid = getpid();
memcpy(&zBuf[sizeof(time_t)], &pid, sizeof(pid));
}else{
read(fd, zBuf, 256);
close(fd);
}
}
#endif
return SQLITE_OK;