From 08a323575d754db4a0cb2432688d83197e1147bf Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 19 Jun 2012 07:21:44 +0000 Subject: Bu::Uuid now uses windows native uuid generation when on windows. Pretty cool. It looks like they put some real effort into it too, it uses macs and everything. You have to link against Rpcrt4.lib/dll i.e. -lRpct4 --- src/unstable/uuid.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp index fb237d8..4ac90a5 100644 --- a/src/unstable/uuid.cpp +++ b/src/unstable/uuid.cpp @@ -11,6 +11,11 @@ #include "bu/membuf.h" #include +#ifdef WIN32 +#include +#include +#endif + Bu::Uuid::Uuid() { clear(); @@ -77,12 +82,31 @@ void Bu::Uuid::clear() Bu::Uuid Bu::Uuid::gen() { +#ifdef linux Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read ); char dat[36]; fIn.read( dat, 36 ); Uuid id; id.set( dat ); return id; +#elif WIN32 + UUID uuid; + UuidCreate( &uuid ); + Uuid id; + id.data[0] = ((unsigned char *)&uuid.Data1)[3]; + id.data[1] = ((unsigned char *)&uuid.Data1)[2]; + id.data[2] = ((unsigned char *)&uuid.Data1)[1]; + id.data[3] = ((unsigned char *)&uuid.Data1)[0]; + id.data[4] = ((unsigned char *)&uuid.Data2)[1]; + id.data[5] = ((unsigned char *)&uuid.Data2)[0]; + id.data[6] = ((unsigned char *)&uuid.Data3)[1]; + id.data[7] = ((unsigned char *)&uuid.Data3)[0]; + memcpy( id.data+8, uuid.Data4, 8 ); + + return id; +#else +# error We should be using one of the other fallbacks, but your platform is not supported yet. Sorry. +#endif } void Bu::Uuid::set( const Bu::String &sSrc ) -- cgit v1.2.3