aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-06-19 07:21:44 +0000
committerMike Buland <eichlan@xagasoft.com>2012-06-19 07:21:44 +0000
commit08a323575d754db4a0cb2432688d83197e1147bf (patch)
treecdca0038a5b130d53813b4806c2dec3836056bac /src
parentbc173f78efb4a813bd673e020cb83bf81d01cf59 (diff)
downloadlibbu++-08a323575d754db4a0cb2432688d83197e1147bf.tar.gz
libbu++-08a323575d754db4a0cb2432688d83197e1147bf.tar.bz2
libbu++-08a323575d754db4a0cb2432688d83197e1147bf.tar.xz
libbu++-08a323575d754db4a0cb2432688d83197e1147bf.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/unstable/uuid.cpp24
1 files changed, 24 insertions, 0 deletions
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 @@
11#include "bu/membuf.h" 11#include "bu/membuf.h"
12#include <string.h> 12#include <string.h>
13 13
14#ifdef WIN32
15#include <rpc.h>
16#include <Rpcdce.h>
17#endif
18
14Bu::Uuid::Uuid() 19Bu::Uuid::Uuid()
15{ 20{
16 clear(); 21 clear();
@@ -77,12 +82,31 @@ void Bu::Uuid::clear()
77 82
78Bu::Uuid Bu::Uuid::gen() 83Bu::Uuid Bu::Uuid::gen()
79{ 84{
85#ifdef linux
80 Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read ); 86 Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read );
81 char dat[36]; 87 char dat[36];
82 fIn.read( dat, 36 ); 88 fIn.read( dat, 36 );
83 Uuid id; 89 Uuid id;
84 id.set( dat ); 90 id.set( dat );
85 return id; 91 return id;
92#elif WIN32
93 UUID uuid;
94 UuidCreate( &uuid );
95 Uuid id;
96 id.data[0] = ((unsigned char *)&uuid.Data1)[3];
97 id.data[1] = ((unsigned char *)&uuid.Data1)[2];
98 id.data[2] = ((unsigned char *)&uuid.Data1)[1];
99 id.data[3] = ((unsigned char *)&uuid.Data1)[0];
100 id.data[4] = ((unsigned char *)&uuid.Data2)[1];
101 id.data[5] = ((unsigned char *)&uuid.Data2)[0];
102 id.data[6] = ((unsigned char *)&uuid.Data3)[1];
103 id.data[7] = ((unsigned char *)&uuid.Data3)[0];
104 memcpy( id.data+8, uuid.Data4, 8 );
105
106 return id;
107#else
108# error We should be using one of the other fallbacks, but your platform is not supported yet. Sorry.
109#endif
86} 110}
87 111
88void Bu::Uuid::set( const Bu::String &sSrc ) 112void Bu::Uuid::set( const Bu::String &sSrc )