mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-24 17:16:21 +00:00
Move code from jid_random_resource() into own function
Move the code that creates a random string into it's own function +get_random_string().
This commit is contained in:
20
src/common.c
20
src/common.c
@@ -489,3 +489,23 @@ get_file_paths_recursive(const char *path, GSList **contents)
|
||||
entry = g_dir_read_name(directory);
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
get_random_string(int length)
|
||||
{
|
||||
GRand *prng;
|
||||
char *rand;
|
||||
char alphabet[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
rand = calloc(length+1, sizeof(char));
|
||||
|
||||
prng = g_rand_new();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < length; i++) {
|
||||
rand[i] = alphabet[g_rand_int_range(prng, 0, sizeof(alphabet))];
|
||||
}
|
||||
g_rand_free(prng);
|
||||
|
||||
return rand;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user