printf-format-fix.h \
process-title.h \
priorityq.h \
- rand.h \
randgen.h \
read-full.h \
restrict-access.h \
#include "ipwd.h"
#include "process-title.h"
#include "var-expand-private.h"
+#include "randgen.h"
#include <fcntl.h>
#include <unistd.h>
void lib_init(void)
{
- struct timeval tv;
i_assert(!lib_initialized);
-
- /* standard way to get rand() return different values. */
- if (gettimeofday(&tv, NULL) < 0)
- i_fatal("gettimeofday(): %m");
- srand((unsigned int) (tv.tv_sec ^ tv.tv_usec ^ getpid()));
-
+ random_init();
data_stack_init();
hostpid_init();
lib_open_non_stdio_dev_null();
env_deinit();
failures_deinit();
process_title_deinit();
+ random_deinit();
}
#include "mempool.h"
#include "imem.h"
#include "byteorder.h"
-#include "rand.h"
typedef struct buffer buffer_t;
typedef struct buffer string_t;
bool lib_is_initialized(void);
void lib_deinit(void);
+uint32_t i_rand(void);
+
#endif
/* Copyright (c) 2014-2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
+#include "randgen.h"
#ifdef HAVE_ARC4RANDOM
#ifdef HAVE_LIBBSD
#include <bsd/stdlib.h>
#endif
-/* this returns [0,RAND_MAX), to keep it compatible with rand() */
-int arc4random_rand(void) {
- return (int)(arc4random() % ((unsigned)RAND_MAX + 1));
+uint32_t i_rand(void)
+{
+ return arc4random();
+}
+#else
+uint32_t i_rand(void)
+{
+ uint32_t value;
+ random_fill(&value, sizeof(value));
+ return value;
}
#endif
+++ /dev/null
-#ifndef RAND_H
-#define RAND_H
-
-#ifdef HAVE_ARC4RANDOM
-
-int arc4random_rand(void);
-#define rand arc4random_rand
-
-#endif
-
-#endif