MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / Generate64RandomChars

Function Generate64RandomChars

extern/nfd/nfd_portal.cpp:824–843  ·  view source on GitHub ↗

Appends up to 64 random chars to the given pointer. Returns the end of the appended chars.

Source from the content-addressed store, hash-verified

822
823// Appends up to 64 random chars to the given pointer. Returns the end of the appended chars.
824char* Generate64RandomChars(char* out) {
825 size_t amount = 32;
826 while (amount > 0) {
827 unsigned char buf[32];
828 ssize_t res = getrandom(buf, amount, 0);
829 if (res == -1) {
830 if (errno == EINTR)
831 continue;
832 else
833 break; // too bad, urandom isn't working well
834 }
835 amount -= res;
836 // we encode each random char using two chars, since they must be [A-Z][a-z][0-9]_
837 for (size_t i = 0; i != static_cast<size_t>(res); ++i) {
838 *out++ = 'A' + static_cast<char>(buf[i] & 15);
839 *out++ = 'A' + static_cast<char>(buf[i] >> 4);
840 }
841 }
842 return out;
843}
844
845constexpr const char STR_RESPONSE_HANDLE_PREFIX[] = "/org/freedesktop/portal/desktop/request/";
846constexpr size_t STR_RESPONSE_HANDLE_PREFIX_LEN =

Callers 1

MakeUniqueObjectPathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected