Files
wizapp-stdlib/src/uuid/uuid.h
Abdelrahman 7ffebe7dce
All checks were successful
Release / release (push) Successful in 3s
Fix missing semi-colon
2026-05-10 02:22:46 +01:00

51 lines
1.3 KiB
C

// vim:fileencoding=utf-8:foldmethod=marker
#ifndef UUID_H
#define UUID_H
#include "../common/aliases/aliases.h"
#include "../common/platform/platform.h"
#include "../base/strings/str8/str8.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#define UUID_BUF_LENGTH 48
#define WAPP_UUID_SPEC WAPP_STR8_SPEC
#define wapp_uuid_varg(WUUID) wapp_str8_varg((WUUID).uuid)
typedef struct WUUID WUUID;
struct WUUID {
Str8 uuid;
};
// TODO (Abdelrahman): Update UUID implementation to work properly with C++ and tests for validation
#ifdef WAPP_PLATFORM_CPP
#define wapp_uuid_gen_uuid4() ([&](){ \
wapp_persist WUUID uuid = wapp_uuid_create(); \
return *(wapp_uuid_init_uuid4(&uuid)); \
}())
#else
#define wapp_uuid_gen_uuid4() *(wapp_uuid_init_uuid4(&wapp_uuid_create()))
#endif
/* Low level UUID API */
#ifdef WAPP_PLATFORM_CPP
#define wapp_uuid_create() ([&](){ return WUUID{wapp_str8_buf(UUID_BUF_LENGTH)}; }())
#else
#define wapp_uuid_create() ((WUUID){.uuid = wapp_str8_buf(UUID_BUF_LENGTH)})
#endif
// Just returns the same pointer that was passed in with the UUID initialised.
// Fails when passed a NULL pointer.
WUUID *wapp_uuid_init_uuid4(WUUID *uuid);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !UUID_H