MCPcopy Create free account
hub / github.com/Kitware/CMake / writeRandomBytes_dev_urandom

Function writeRandomBytes_dev_urandom

Utilities/cmexpat/lib/xmlparse.c:1079–1104  ·  view source on GitHub ↗

Extract entropy from /dev/urandom */

Source from the content-addressed store, hash-verified

1077
1078/* Extract entropy from /dev/urandom */
1079static int
1080writeRandomBytes_dev_urandom(void *target, size_t count) {
1081 int success = 0; /* full count bytes written? */
1082 size_t bytesWrittenTotal = 0;
1083
1084 const int fd = open("/dev/urandom", O_RDONLY);
1085 if (fd < 0) {
1086 return 0;
1087 }
1088
1089 do {
1090 void *const currentTarget = (void *)((char *)target + bytesWrittenTotal);
1091 const size_t bytesToWrite = count - bytesWrittenTotal;
1092
1093 const ssize_t bytesWrittenMore = read(fd, currentTarget, bytesToWrite);
1094
1095 if (bytesWrittenMore > 0) {
1096 bytesWrittenTotal += bytesWrittenMore;
1097 if (bytesWrittenTotal >= count)
1098 success = 1;
1099 }
1100 } while (! success && (errno == EINTR));
1101
1102 close(fd);
1103 return success;
1104}
1105
1106# endif /* ! defined(_WIN32) && defined(XML_DEV_URANDOM) */
1107

Callers 1

Calls 1

readFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…