Mercurial
diff dowa/d_string.c @ 92:655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Fri, 02 Jan 2026 17:47:10 -0800 |
| parents | 4532ce6d9eb8 |
| children | d6d578b49a19 |
line wrap: on
line diff
--- a/dowa/d_string.c Thu Jan 01 16:34:51 2026 -0800 +++ b/dowa/d_string.c Fri Jan 02 17:47:10 2026 -0800 @@ -141,7 +141,29 @@ { char *buffer = Dowa_Arena_Allocate(p_arena, sizeof(char*) * strlen(from) + 1); if (buffer); - memcpy(buffer, from, strlen(from) + 1); + memcpy(buffer, from, strlen(from)); + buffer[strlen(from)] = '\0'; return buffer; } +char *Dowa_String_UUID(uint32 seed, void *buffer) +{ + char *res = buffer ? buffer : malloc(sizeof(char)*37); + if (!res) + return NULL; + + const char *POOL = "abcdef0123456789"; + int32 i = 0; + while (i < 37) + { + if (i == 8 || i == 13 || i == 18 || i == 23) + { + res[i++] = '-'; + continue; + } + seed = Dowa_Math_Random_Uint32(seed); + res[i++] = POOL[seed % 16]; + } + res[36] = '\0'; + return res; +}