Recreate base64 project

This commit is contained in:
2025-08-10 23:30:27 +01:00
commit e90d14344e
63 changed files with 11139 additions and 0 deletions

59
wapp/uuid/uuid.c Normal file
View File

@@ -0,0 +1,59 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "uuid.h"
#include "../common/aliases/aliases.h"
#include "../common/assert/assert.h"
#include "../primitives/strings/str8/str8.h"
#include "../prng/xorshift/xorshift.h"
#include <stdbool.h>
#include <inttypes.h>
#define UUID_STR_FORMAT ("%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.12" PRIx64)
typedef struct uuid4 UUID4;
struct uuid4 {
u64 high;
u64 low;
};
internal UUID4 generate_uuid4(void);
internal void uuid4_to_uuid(const UUID4* uuid4, UUID *uuid);
UUID *wapp_uuid_init_uuid4(UUID *uuid) {
wapp_debug_assert(uuid != NULL, "`uuid` should not be NULL");
UUID4 uuid4 = generate_uuid4();
uuid4_to_uuid(&uuid4, uuid);
return uuid;
}
internal UUID4 generate_uuid4(void) {
persistent XOR256State state = {0};
persistent bool initialised = false;
if (!initialised) {
initialised = true;
state = wapp_prng_xorshift_init_state();
}
UUID4 uuid = (UUID4){
.high = wapp_prng_xorshift_256(&state),
.low = wapp_prng_xorshift_256(&state),
};
uuid.high = (uuid.high & 0xffffffffffff0fff) | 0x0000000000004000;
uuid.low = (uuid.low & 0x3fffffffffffffff) | 0x8000000000000000;
return uuid;
}
internal void uuid4_to_uuid(const UUID4* uuid4, UUID *uuid) {
u64 grp1 = uuid4->high >> 32;
u64 grp2 = (uuid4->high << 32) >> 48;
u64 grp3 = (uuid4->high << 48) >> 48;
u64 grp4 = uuid4->low >> 48;
u64 grp5 = (uuid4->low << 16) >> 16;
wapp_str8_format(&(uuid->uuid), UUID_STR_FORMAT, grp1, grp2, grp3, grp4, grp5);
}

37
wapp/uuid/uuid.h Normal file
View File

@@ -0,0 +1,37 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef UUID_H
#define UUID_H
#include "../common/aliases/aliases.h"
#include "../common/platform/platform.h"
#include "../primitives/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(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.
// Fails when passed a NULL pointer.
UUID *wapp_uuid_init_uuid4(UUID *uuid);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !UUID_H

10
wapp/uuid/wapp_uuid.c Normal file
View File

@@ -0,0 +1,10 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef WAPP_UUID_C
#define WAPP_UUID_C
#include "uuid.c"
#include "../primitives/wapp_primitives.c"
#include "../prng/wapp_prng.c"
#endif // !WAPP_UUID_C

11
wapp/uuid/wapp_uuid.h Normal file
View File

@@ -0,0 +1,11 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef WAPP_UUID_H
#define WAPP_UUID_H
#include "uuid.h"
#include "../common/wapp_common.h"
#include "../primitives/wapp_primitives.h"
#include "../prng/wapp_prng.h"
#endif // !WAPP_UUID_H