Ticket #303: win32-uuid-cleanup.patch
File win32-uuid-cleanup.patch, 2.1 KB (added by , 16 years ago) |
---|
-
common/win32_uuid.cc
22 22 23 23 #include "win32_uuid.h" 24 24 25 #include <xapian/error.h> 25 #include "xapian/error.h" 26 27 #include <cstring> 28 29 using namespace std; 30 31 /// The size of a UUID in bytes. 32 const size_t UUID_SIZE = 16; 33 34 /// The size of a UUID string in bytes (not including trailing '\0'). 35 const size_t UUID_STRING_SIZE = 36; 26 36 27 37 void 28 38 uuid_generate(uuid_t uu) 29 39 { 30 40 UUID uuid; 31 if ( UuidCreate(&uuid) != RPC_S_OK) {41 if (rare(UuidCreate(&uuid) != RPC_S_OK)) { 32 42 // Throw a DatabaseCreateError, since we can't make a UUID. The 33 43 // windows API documentation is a bit unclear about the situations in 34 44 // which this can happen, but if this behaviour causes a problem, an … … 36 46 // situation. 37 47 throw Xapian::DatabaseCreateError("Cannot create UUID"); 38 48 } 39 memcpy(uu, &uuid, 16);49 memcpy(uu, &uuid, UUID_SIZE); 40 50 } 41 51 42 52 int … … 45 55 UUID uuid; 46 56 if (UuidFromString((unsigned char*)in, &uuid) != RPC_S_OK) 47 57 return -1; 48 memcpy(uu, &uuid, 16);58 memcpy(uu, &uuid, UUID_SIZE); 49 59 return 0; 50 60 } 51 61 52 void uuid_unparse_lower(const uuid_t uu, char * 62 void uuid_unparse_lower(const uuid_t uu, char * out) 53 63 { 54 64 UUID uuid; 55 65 char *uuidstr; 56 memcpy(&uuid, uu, 16); 57 if (UuidToString(&uuid, (unsigned char **)(&uuidstr)) != RPC_S_OK) 58 return; 59 int uuidlen = strlen(uuidstr); 60 strncpy( out, strlwr(uuidstr), uuidlen ); 66 memcpy(&uuid, uu, UUID_SIZE); 67 if (rare(UuidToString(&uuid, (unsigned char **)(&uuidstr)) != RPC_S_OK)) { 68 // The only documented (or really conceivable) error code is 69 // RPC_S_OUT_OF_MEMORY. 70 throw std::bad_alloc(); 71 } 72 memcpy(out, strlwr(uuidstr), UUID_STRING_SIZE); 73 out[UUID_STRING_SIZE] = '\0'; 61 74 RpcStringFree((unsigned char**)(&uuidstr)); 62 75 } 63 76 64 77 void uuid_clear(uuid_t uu) 65 78 { 66 memset(uu, 0 x00, 16);79 memset(uu, 0, UUID_SIZE); 67 80 } 68 81 69 82 int uuid_is_null(const uuid_t uu) 70 83 { 71 84 int i = 0; 72 while (i < 16) {85 while (i < UUID_SIZE) { 73 86 if (uu[i++]) 74 87 return 0; 75 88 }