48 lines
1.2 KiB
C
48 lines
1.2 KiB
C
|
//
|
||
|
// Created by nicol on 2018-03-18.
|
||
|
//
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <time.h>
|
||
|
#include <stdio.h>
|
||
|
#include "uuid.h"
|
||
|
|
||
|
const esc_uuid_t* esc_uuid_create() {
|
||
|
esc_uuid_t* result = malloc(sizeof(esc_uuid_t));
|
||
|
srand(time(NULL));
|
||
|
for(int i=0;i<16;i++)
|
||
|
result->data[i] = (uint8_t)(rand() & 0xff);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
const esc_uuid_t* esc_uuid_from(uint8_t* src, size_t size) {
|
||
|
if (size != 16) {
|
||
|
return 0;
|
||
|
}
|
||
|
esc_uuid_t* uuid = malloc(sizeof(esc_uuid_t));
|
||
|
for (size_t i=0; i<size; i++)
|
||
|
uuid->data[i] = src[i];
|
||
|
return uuid;
|
||
|
}
|
||
|
|
||
|
const char* esc_uuid_format(const esc_uuid_t* uuid, char* buffer, size_t buf_size) {
|
||
|
snprintf(buffer, buf_size, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||
|
uuid->data[0],
|
||
|
uuid->data[1],
|
||
|
uuid->data[2],
|
||
|
uuid->data[3],
|
||
|
uuid->data[4],
|
||
|
uuid->data[5],
|
||
|
uuid->data[6],
|
||
|
uuid->data[7],
|
||
|
uuid->data[8],
|
||
|
uuid->data[9],
|
||
|
uuid->data[10],
|
||
|
uuid->data[11],
|
||
|
uuid->data[12],
|
||
|
uuid->data[13],
|
||
|
uuid->data[14],
|
||
|
uuid->data[15]);
|
||
|
return buffer;
|
||
|
}
|