From 6d1d4d0a5506dce90c833ef8dd141058fea3c33a Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Mon, 25 Dec 2023 06:05:40 -0600 Subject: [WIP] Add instances still need to do the following: - check if the folder exists - try and find some way to canonicalize the path name --- src/uuid/uuid.c | 23 ++++++++++++++--------- src/uuid/uuid.h | 5 +++++ 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src/uuid') diff --git a/src/uuid/uuid.c b/src/uuid/uuid.c index 0d49f0b..0dfcfbd 100644 --- a/src/uuid/uuid.c +++ b/src/uuid/uuid.c @@ -11,8 +11,8 @@ void l2_uuid__set_version(uuid_t *id, unsigned version) { version &= 0x0F; - id->halves[1] &= ~(UINT64_C(0x0F) << 12); - id->halves[1] |= (uint64_t)version << 12; + id->uuid_ms &= ~(UINT64_C(0x0F) << 12); + id->uuid_ms |= (uint64_t)version << 12; } void l2_uuid__set_variant(uuid_t *id, unsigned variant, unsigned bits) @@ -21,8 +21,8 @@ void l2_uuid__set_variant(uuid_t *id, unsigned variant, unsigned bits) uint64_t lvariant = (uint64_t)variant << (64 - bits); lvariant &= ~mask; - id->halves[0] &= mask; - id->halves[0] |= lvariant; + id->uuid_ls &= mask; + id->uuid_ls |= lvariant; } void l2_uuid_random(uuid_t *id) @@ -35,11 +35,11 @@ void l2_uuid_random(uuid_t *id) void l2_uuid_to_string(const uuid_t *id, char *out) { snprintf(out, UUID_STRLEN + 1, "%08" PRIx64 "-%04" PRIx64 "-%04" PRIx64 "-%04" PRIx64 "-%012" PRIx64, - id->halves[1] >> 32, /* time-low */ - id->halves[1] >> 16 & 0xffff, /* time-mid */ - id->halves[1] & 0xffff, /* time-high-and-version */ - id->halves[0] >> 48, /* clock-seq-and-reserved, clock-seq-low */ - id->halves[0] & UINT64_C(0xffffffffffff)); /* node */ + id->uuid_ms >> 32, /* time-low */ + id->uuid_ms >> 16 & 0xffff, /* time-mid */ + id->uuid_ms & 0xffff, /* time-high-and-version */ + id->uuid_ls >> 48, /* clock-seq-and-reserved, clock-seq-low */ + id->uuid_ls & UINT64_C(0xffffffffffff)); /* node */ } void l2_uuid_to_string_short(const uuid_t *id, char *out) @@ -78,6 +78,11 @@ bool l2_uuid_from_string_short(uuid_t *id, const char *str) return true; } +int l2_uuid_compare(const uuid_t *c1, const uuid_t *c2) +{ + return memcmp(c1, c2, sizeof(uuid_t)); +} + /* This function exists because there's not a portable way to do this. * Don't suggest strtoull, because uint64_t may not be a ulonglong. */ bool l2__str_to_uint64(uint64_t *out, const char *str) diff --git a/src/uuid/uuid.h b/src/uuid/uuid.h index 740fa17..7ddeeb4 100644 --- a/src/uuid/uuid.h +++ b/src/uuid/uuid.h @@ -9,6 +9,9 @@ typedef union tag_uuid_t { uint8_t bytes[16]; uint64_t halves[2]; + +#define uuid_ls halves[0] +#define uuid_ms halves[1] } uuid_t; #define UUID_NULL_INIT { { 0 } } @@ -24,4 +27,6 @@ void l2_uuid_to_string_short(const uuid_t *id, char *out); bool l2_uuid_from_string(uuid_t *id, const char *str); bool l2_uuid_from_string_short(uuid_t *id, const char *str); +int l2_uuid_compare(const uuid_t *c1, const uuid_t *c2); + #endif /* include guard */ -- cgit v1.2.3-70-g09d2