Add UUIDv4 generator

This commit is contained in:
Abdelrahman Said
2025-03-22 02:27:59 +00:00
parent 74428f1caf
commit c83c652b37
6 changed files with 112 additions and 0 deletions

34
src/uuid/uuid.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef UUID_H
#define UUID_H
#include "../common/aliases/aliases.h"
#include "../core/strings/str8/str8.h"
#ifdef __cplusplus
BEGIN_C_LINKAGE
#endif // __cplusplus
#define UUID_BUF_LENGTH 48
#define WAPP_UUID_SPEC WAPP_STR8_SPEC
#define wapp_uuid_varg(UUID) wapp_str8_varg((UUID).uuid)
typedef struct uuid UUID;
struct uuid {
Str8 uuid;
};
#define wapp_uuid_gen_uuid4() *(wapp_uuid_init_uuid4(&wapp_uuid_create()))
/* Low level UUID API */
#define wapp_uuid_create() ((UUID){.uuid = wapp_str8_buf(UUID_BUF_LENGTH)})
// Just returns the same pointer that was passed in with the UUID initialised.
// If the pointer is NULL, it skips initialisation.
UUID *wapp_uuid_init_uuid4(UUID *uuid);
#ifdef __cplusplus
END_C_LINKAGE
#endif // __cplusplus
#endif // !UUID_H