Copy UUID implementation

This commit is contained in:
shermp
2019-06-09 17:02:00 +12:00
parent 5c6a52d651
commit c011fcd5dd
2 changed files with 23 additions and 0 deletions

View File

@@ -64,4 +64,5 @@ void mvhd_buffer_to_footer(MVHDFooter* footer, uint8_t* buffer);
void mvhd_buffer_to_header(MVHDSparseHeader* header, uint8_t* buffer);
void mvhd_footer_to_buffer(MVHDFooter* footer, uint8_t* buffer);
void mvhd_header_to_buffer(MVHDSparseHeader* header, uint8_t* buffer);
void mvhd_generate_uuid(uint8_t *uuid);
#endif

View File

@@ -1,5 +1,8 @@
#include <stdbool.h>
#include <string.h>
#ifdef HAVE_UUID_H
#include <uuid/uuid.h>
#endif
#include "minivhd_internal.h"
#include "minivhd.h"
@@ -53,4 +56,23 @@ MVHDGeom mvhd_calculate_geometry(int size_mb, int* new_size) {
*new_size = chs.cyl * chs.heads * chs.spt * MVHD_SECTOR_SIZE;
return chs;
}
/* A UUID is required, but there are no restrictions on how it needs
to be generated. */
void mvhd_generate_uuid(uint8_t *uuid)
{
#if defined(HAVE_UUID_H)
uuid_generate(guid);
#else
int n;
srand(time(NULL));
for (n = 0; n < 16; n++) {
uuid[n] = rand();
}
uuid[6] &= 0x0F;
uuid[6] |= 0x40; /* Type 4 */
uuid[8] &= 0x3F;
uuid[8] |= 0x80; /* Variant 1 */
#endif
}