Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 91:19cccf6e866a | 92:655ea0b661fd |
|---|---|
| 139 | 139 |
| 140 char *Dowa_String_Copy_Arena(char *from, Dowa_Arena *p_arena) | 140 char *Dowa_String_Copy_Arena(char *from, Dowa_Arena *p_arena) |
| 141 { | 141 { |
| 142 char *buffer = Dowa_Arena_Allocate(p_arena, sizeof(char*) * strlen(from) + 1); | 142 char *buffer = Dowa_Arena_Allocate(p_arena, sizeof(char*) * strlen(from) + 1); |
| 143 if (buffer); | 143 if (buffer); |
| 144 memcpy(buffer, from, strlen(from) + 1); | 144 memcpy(buffer, from, strlen(from)); |
| 145 buffer[strlen(from)] = '\0'; | |
| 145 return buffer; | 146 return buffer; |
| 146 } | 147 } |
| 147 | 148 |
| 149 char *Dowa_String_UUID(uint32 seed, void *buffer) | |
| 150 { | |
| 151 char *res = buffer ? buffer : malloc(sizeof(char)*37); | |
| 152 if (!res) | |
| 153 return NULL; | |
| 154 | |
| 155 const char *POOL = "abcdef0123456789"; | |
| 156 int32 i = 0; | |
| 157 while (i < 37) | |
| 158 { | |
| 159 if (i == 8 || i == 13 || i == 18 || i == 23) | |
| 160 { | |
| 161 res[i++] = '-'; | |
| 162 continue; | |
| 163 } | |
| 164 seed = Dowa_Math_Random_Uint32(seed); | |
| 165 res[i++] = POOL[seed % 16]; | |
| 166 } | |
| 167 res[36] = '\0'; | |
| 168 return res; | |
| 169 } |