1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Factor out base 36 generation to separate function

This is so it can be reused without having to copy-paste.

generateBase36() is guaranateed to completely initialize and
null-terminate the buffer that is passed in.
This commit is contained in:
Misa 2021-05-20 14:10:45 -07:00 committed by Ethan Lee
parent 766782da5d
commit 3bcb6938f7

View file

@ -244,13 +244,12 @@ static bool FILESYSTEM_exists(const char *fname)
return PHYSFS_exists(fname);
}
static void generateVirtualMountPath(char* path, const size_t path_size)
static void generateBase36(char* string, const size_t string_size)
{
char random[6 + 1] = {'\0'};
size_t i;
for (i = 0; i < SDL_arraysize(random) - 1; ++i)
for (i = 0; i < string_size - 1; ++i)
{
/* Generate a-z0-9 (base 36) */
/* a-z0-9 */
char randchar = fRandom() * 36;
if (randchar <= 26)
{
@ -261,13 +260,20 @@ static void generateVirtualMountPath(char* path, const size_t path_size)
randchar -= 26;
randchar += '0';
}
random[i] = randchar;
string[i] = randchar;
}
string[string_size - 1] = '\0';
}
static void generateVirtualMountPath(char* path, const size_t path_size)
{
char random_str[6 + 1];
generateBase36(random_str, sizeof(random_str));
SDL_snprintf(
path,
path_size,
".vvv-mnt-virtual-%s/custom-assets/",
random
random_str
);
}