From 17589534d0ccff05463910d1f0ba673d7d1630fd Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" Date: Wed, 16 Oct 2013 11:15:27 +0100 Subject: Add support for arc4random If arc4random is present it will be used over the srand/rand interface. This fixes some warnings in OpenBSD-current. --- src/tool/tool.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/tool') diff --git a/src/tool/tool.c b/src/tool/tool.c index 1bb3ebe6..3b9cc255 100644 --- a/src/tool/tool.c +++ b/src/tool/tool.c @@ -144,11 +144,16 @@ ngt_RandomStr(char *String, const size_t len) assert(String != NULL); gettimeofday(&t, NULL); +#ifndef HAVE_ARC4RANDOM srand((unsigned)(t.tv_usec * t.tv_sec)); for (i = 0; i < len; ++i) { String[i] = chars[rand() % (sizeof(chars) - 1)]; } +#else + for (i = 0; i < len; ++i) + String[i] = chars[arc4random() % (sizeof(chars) - 1)]; +#endif String[len] = '\0'; return String; -- cgit 1.4.1