diff options
Diffstat (limited to 'contrib/bc/src/rand.c')
-rw-r--r-- | contrib/bc/src/rand.c | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/contrib/bc/src/rand.c b/contrib/bc/src/rand.c index a66728246fbc..6b2ec7bdb30f 100644 --- a/contrib/bc/src/rand.c +++ b/contrib/bc/src/rand.c @@ -1,34 +1,6 @@ /* * ***************************************************************************** * - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2018-2019 Gavin D. Howard and contributors. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * ***************************************************************************** - * * Parts of this code are adapted from the following: * * PCG, A Family of Better Random Number Generators. @@ -38,9 +10,10 @@ * * ----------------------------------------------------------------------------- * - * Parts of this code are also under the following license: + * This code is under the following license: * * Copyright (c) 2014-2017 Melissa O'Neill and PCG Project contributors + * Copyright (c) 2018-2021 Gavin D. Howard and contributors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -179,7 +152,7 @@ static ulong bc_rand_frand(void *ptr) { nread = read(fd, buf, sizeof(ulong)); - if (BC_ERR(nread != sizeof(ulong))) bc_vm_err(BC_ERR_FATAL_IO_ERR); + if (BC_ERR(nread != sizeof(ulong))) bc_vm_fatalError(BC_ERR_FATAL_IO_ERR); return *((ulong*) buf); } @@ -289,6 +262,15 @@ void bc_rand_srand(BcRNGData *rng) { bc_rand_fill(rng, bc_rand_frand, &fd); close(fd); } + else { + + fd = open("/dev/random", O_RDONLY); + + if (BC_NO_ERR(fd >= 0)) { + bc_rand_fill(rng, bc_rand_frand, &fd); + close(fd); + } + } while (BC_ERR(BC_RAND_ZERO(rng))) bc_rand_fill(rng, bc_rand_rand, NULL); |