LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
uuid.c
Go to the documentation of this file.
1#include <uuid.h>
2#include <string.h>
3
4uuid_key_t uuid_key(uuid_t* uuid) {
5 uuid_key_t key = 0;
6
7 for(uint8_t i = 0; i < sizeof(uuid->data); ++i) {
8 key ^= uuid->data[i];
9 }
10
11 return key;
12}
13
14int uuid_cmp(uuid_t* a, uuid_t* b) {
15 return memcmp(a->data, b->data, sizeof(a->data));
16}
17
18size_t uuid_fmt(char* buffer, size_t len, uuid_t* uuid) {
19 return ksnprintf(buffer, len,
20 "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
21 (uint64_t)uuid->a, (uint64_t)uuid->b, (uint64_t)uuid->c, (uint64_t)uuid->d,
22 (uint64_t)uuid->e[0], (uint64_t)uuid->e[1], (uint64_t)uuid->e[2],
23 (uint64_t)uuid->e[3], (uint64_t)uuid->e[4], (uint64_t)uuid->e[5]
24 );
25}
unsigned long uint64_t
Definition arch.h:14
unsigned char uint8_t
Definition arch.h:5
size_t ksnprintf(char *buffer, size_t buffer_size, const char *format,...)
Definition string.c:339
int memcmp(const void *s1, const void *s2, size_t size)
Definition string.c:91
uuid_key_t uuid_key(uuid_t *uuid)
Definition uuid.c:4
size_t uuid_fmt(char *buffer, size_t len, uuid_t *uuid)
Definition uuid.c:18
int uuid_cmp(uuid_t *a, uuid_t *b)
Definition uuid.c:14
uint8_t data[16]
Definition uuid.h:15
Definition uuid.h:6