mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-30 19:17:36 +00:00
Make some style fixes to prng code
This commit is contained in:
parent
dab6d7a345
commit
98861b23fc
3 changed files with 9 additions and 5 deletions
|
@ -114,7 +114,8 @@ static ssize_t GetDevUrandom(char *p, size_t n, unsigned f) {
|
|||
ssize_t __getrandom(void *p, size_t n, unsigned f) {
|
||||
ssize_t rc;
|
||||
if (IsWindows()) {
|
||||
rc = ProcessPrng(p, n) ? n : __winerr();
|
||||
ProcessPrng(p, n); // never fails
|
||||
rc = n;
|
||||
} else if (have_getrandom) {
|
||||
if (IsXnu() || IsOpenbsd()) {
|
||||
rc = GetRandomBsd(p, n, GetRandomEntropy);
|
||||
|
@ -184,9 +185,7 @@ ssize_t __getrandom(void *p, size_t n, unsigned f) {
|
|||
* @raise EFAULT if the `n` bytes at `p` aren't valid memory
|
||||
* @raise EINTR if we needed to block and a signal was delivered instead
|
||||
* @cancelationpoint
|
||||
* @asyncsignalsafe
|
||||
* @restartable
|
||||
* @vforksafe
|
||||
*/
|
||||
ssize_t getrandom(void *p, size_t n, unsigned f) {
|
||||
ssize_t rc;
|
||||
|
|
|
@ -997,8 +997,10 @@ textwindows ssize_t ReadBuffer(int fd, void *data, size_t size, int64_t offset,
|
|||
if (f->kind == kFdDevNull)
|
||||
return 0;
|
||||
|
||||
if (f->kind == kFdDevRandom)
|
||||
return ProcessPrng(data, size) ? size : __winerr();
|
||||
if (f->kind == kFdDevRandom) {
|
||||
ProcessPrng(data, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
if (f->kind == kFdConsole)
|
||||
return ReadFromConsole(f, data, size, waitmask);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/strace.h"
|
||||
#include "libc/runtime/syslib.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
int sys_getentropy(void *, size_t) asm("sys_getrandom");
|
||||
|
@ -39,6 +40,8 @@ int getentropy(void *p, size_t n) {
|
|||
rc = eio();
|
||||
} else if ((!p && n)) {
|
||||
rc = efault();
|
||||
} else if (IsXnuSilicon()) {
|
||||
rc = __syslib->__getentropy(p, n);
|
||||
} else if (IsXnu() || IsOpenbsd()) {
|
||||
rc = sys_getentropy(p, n);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue