diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-10-19 09:03:51 +0100 |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2015-02-09 23:14:17 +0000 |
commit | fcd88e9ee0c68c5f0e15fb402c22b26dc4415299 (patch) | |
tree | 4397baf7f83f5dc26ec66c99440934f20c89c3cc /common/gvfsutils.c | |
parent | 221378f58f50bdf6e780e668539e875bac581826 (diff) | |
download | gvfs-fcd88e9ee0c68c5f0e15fb402c22b26dc4415299.tar.gz |
daemon: Move random string generation into shared lib
Random string generation is used in a few different places, so share the
implementation.
https://bugzilla.gnome.org/show_bug.cgi?id=738967
Diffstat (limited to 'common/gvfsutils.c')
-rw-r--r-- | common/gvfsutils.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/common/gvfsutils.c b/common/gvfsutils.c new file mode 100644 index 00000000..87718f30 --- /dev/null +++ b/common/gvfsutils.c @@ -0,0 +1,42 @@ +/* GIO - GLib Input, Output and Streaming Library + * + * Copyright (C) 2014 Ross Lagerwall + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see + * <http://www.gnu.org/licenses/>. + */ + +#include <config.h> + +#include <string.h> +#include <glib.h> +#include "gvfsutils.h" + +/** + * gvfs_randomize_string: + * @str: the string to randomize + * @len: the length of the string + * + * Takes a string and fills it with @len random chars. + **/ +void +gvfs_randomize_string (char *str, + int len) +{ + int i; + const char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + + for (i = 0; i < len; i++) + str[i] = chars[g_random_int_range (0, strlen(chars))]; +} |