Commit 9a41f307 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Add a simple srandomdev() implementation inspired by the one in FreeBSD.

git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@766 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent d740cd67
......@@ -61,6 +61,7 @@ AC_FUNC_VPRINTF
AC_CHECK_FUNCS([strerror])
AC_FUNC_STRERROR_R
AC_CHECK_FUNCS([socket])
AC_CHECK_FUNCS([srandomdev])
AC_CHECK_FUNCS([strlcat])
AC_CHECK_FUNCS([strlcpy])
......
......@@ -6,6 +6,7 @@ noinst_HEADERS = \
cli_common.h \
cli_priv.h \
compat/asprintf.h \
compat/srandomdev.h \
compat/strlcat.h \
compat/strlcpy.h \
compat/vasprintf.h \
......
/*
* $Id$
*/
#ifndef COMPAT_SRANDOMDEV_H_INCLUDED
#define COMPAT_SRANDOMDEV_H_INCLUDED
#ifndef HAVE_SRANDOMDEV
void srandomdev(void);
#endif
#endif
......@@ -7,6 +7,7 @@ lib_LIBRARIES = libcompat.a
libcompat_a_SOURCES = \
asprintf.c \
vasprintf.c \
srandomdev.c \
strlcat.c \
strlcpy.c
......
/*
* $Id$
*/
#ifndef HAVE_SRANDOMDEV
#include <sys/time.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "compat/srandomdev.h"
void
srandomdev(void)
{
struct timeval tv;
unsigned int seed;
int fd;
if ((fd = open("/dev/random", O_RDONLY)) >= 0) {
read(fd, &seed, sizeof seed);
close(fd);
} else {
gettimeofday(&tv, NULL);
/* NOTE: intentional use of uninitialized variable */
seed ^= (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec;
}
srandom(seed);
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment