| OLD | NEW |
| 1 // Copyright (c) 2007, Google Inc. | 1 // Copyright (c) 2007, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 *reinterpret_cast<uint32_t*>(&guid->data4[4]) = random(); | 59 *reinterpret_cast<uint32_t*>(&guid->data4[4]) = random(); |
| 60 return true; | 60 return true; |
| 61 } | 61 } |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 // Guid generator. | 64 // Guid generator. |
| 65 const GUIDGenerator kGuidGenerator; | 65 const GUIDGenerator kGuidGenerator; |
| 66 | 66 |
| 67 bool CreateGUID(GUID *guid) { | 67 bool CreateGUID(GUID *guid) { |
| 68 return kGuidGenerator.CreateGUID(guid); | 68 return kGuidGenerator.CreateGUID(guid); |
| 69 }; | 69 } |
| 70 | 70 |
| 71 // Parse guid to string. | 71 // Parse guid to string. |
| 72 bool GUIDToString(const GUID *guid, char *buf, int buf_len) { | 72 bool GUIDToString(const GUID *guid, char *buf, int buf_len) { |
| 73 // Should allow more space the the max length of GUID. | 73 // Should allow more space the the max length of GUID. |
| 74 assert(buf_len > kGUIDStringLength); | 74 assert(buf_len > kGUIDStringLength); |
| 75 int num = snprintf(buf, buf_len, kGUIDFormatString, | 75 int num = snprintf(buf, buf_len, kGUIDFormatString, |
| 76 guid->data1, guid->data2, guid->data3, | 76 guid->data1, guid->data2, guid->data3, |
| 77 *reinterpret_cast<const uint32_t *>(&(guid->data4[0])), | 77 *reinterpret_cast<const uint32_t *>(&(guid->data4[0])), |
| 78 *reinterpret_cast<const uint32_t *>(&(guid->data4[4]))); | 78 *reinterpret_cast<const uint32_t *>(&(guid->data4[4]))); |
| 79 if (num != kGUIDStringLength) | 79 if (num != kGUIDStringLength) |
| 80 return false; | 80 return false; |
| 81 | 81 |
| 82 buf[num] = '\0'; | 82 buf[num] = '\0'; |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| OLD | NEW |