MCPcopy Create free account
hub / github.com/antirez/ds4 / web_random_bytes

Function web_random_bytes

ds4_web.c:320–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318}
319
320static void web_random_bytes(unsigned char *buf, size_t len) {
321 int fd = open("/dev/urandom", O_RDONLY);
322 if (fd >= 0) {
323 size_t off = 0;
324 while (off < len) {
325 ssize_t n = read(fd, buf + off, len - off);
326 if (n < 0 && errno == EINTR) continue;
327 if (n <= 0) break;
328 off += (size_t)n;
329 }
330 close(fd);
331 if (off == len) return;
332 }
333 uint64_t x = (uint64_t)time(NULL) ^ ((uint64_t)getpid() << 32);
334 for (size_t i = 0; i < len; i++) {
335 x = x * 6364136223846793005ULL + 1;
336 buf[i] = (unsigned char)(x >> 32);
337 }
338}
339
340static char *web_base64(const unsigned char *data, size_t len) {
341 static const char tab[] =

Callers 3

web_ws_connectFunction · 0.85
web_ws_send_textFunction · 0.85
web_ws_send_pongFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected