Index: base/rand_util_posix.cc |
diff --git a/base/rand_util_posix.cc b/base/rand_util_posix.cc |
index 43dfd1e7904914e71eea5eb235526ab42cecde48..6a0a203f6347176fae4282448cd95ab1c799fb98 100644 |
--- a/base/rand_util_posix.cc |
+++ b/base/rand_util_posix.cc |
@@ -12,6 +12,7 @@ |
#include "base/file_util.h" |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
+#include "base/stringprintf.h" |
namespace { |
@@ -54,6 +55,22 @@ uint64 RandUint64() { |
return number; |
} |
+// TODO(cmasone): Once we're comfortable this works, migrate Windows code to |
+// use this as well. |
+std::string RandomBytesToGUIDString(const uint64 bytes[2]) { |
+ return StringPrintf("%08X-%04X-%04X-%04X-%012llX", |
+ static_cast<unsigned int>(bytes[0] >> 32), |
+ static_cast<unsigned int>((bytes[0] >> 16) & 0x0000ffff), |
+ static_cast<unsigned int>(bytes[0] & 0x0000ffff), |
+ static_cast<unsigned int>(bytes[1] >> 48), |
+ bytes[1] & 0x0000ffffffffffffULL); |
+} |
+ |
+std::string GenerateGUID() { |
+ uint64 sixteen_bytes[2] = { base::RandUint64(), base::RandUint64() }; |
+ return RandomBytesToGUIDString(sixteen_bytes); |
+} |
+ |
} // namespace base |
int GetUrandomFD(void) { |