diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2019-01-24 14:18:17 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2019-01-24 14:21:57 +0100 |
commit | 22a07d791bf74b7c6478058e8b1c91018b1bc2f7 (patch) | |
tree | d9900b963cf331a3a6cb69061576c76800a88501 /src/utils.c | |
parent | 476d6b28848f952c09a094e2227f20d69d4f1482 (diff) | |
parent | cea2b50c81db45d3f0eb19c327d2cc04bc01e1d2 (diff) |
Merge branch 'master' into releasev1.32
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c index 66ed4c0..462d688 100644 --- a/src/utils.c +++ b/src/utils.c @@ -5,7 +5,7 @@ * Copyright (c) 2004-2011, Daniel Stoedle <daniels@cs.uit.no>, * Yellow Lemon Software. All rights reserved. * - * Copyright (c) 2017 Toni Uhlig <matzeton@googlemail.com> + * Copyright (c) 2017-2019, Toni Uhlig <matzeton@googlemail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -43,8 +43,15 @@ * Note that the source code is best viewed with tabs set to 4 spaces. */ +#include <stdio.h> +#include <stdlib.h> #include <stdarg.h> #include <string.h> +#include <time.h> +#include <assert.h> +#ifdef HAVE_ARC4RANDOM +#include <bsd/stdlib.h> +#endif #ifndef WIN32 #include <syslog.h> @@ -142,3 +149,23 @@ void print_hexstr(unsigned char *buf, size_t siz) { free(out); } #endif + +int pt_random(void) { +#ifdef HAVE_ARC4RANDOM + return arc4random(); +#else +#ifdef HAVE_RANDOM +#ifndef TIME_UTC +#define TIME_UTC 1 +#endif + struct timespec ts; + + assert(timespec_get(&ts, TIME_UTC)); + srandom(ts.tv_nsec ^ ts.tv_sec); + return random(); +#else + srand(time(0)); + return rand(); +#endif +#endif +} |