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 | |
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')
-rw-r--r-- | common/Makefile.am | 1 | ||||
-rw-r--r-- | common/gvfsutils.c | 42 | ||||
-rw-r--r-- | common/gvfsutils.h | 30 |
3 files changed, 73 insertions, 0 deletions
diff --git a/common/Makefile.am b/common/Makefile.am index 0577d677..ac860ce7 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -28,6 +28,7 @@ libgvfscommon_la_SOURCES = \ gvfsdaemonprotocol.c gvfsdaemonprotocol.h \ gvfsicon.h gvfsicon.c \ gvfsfileinfo.c gvfsfileinfo.h \ + gvfsutils.c gvfsutils.h \ $(dbus_built_sources) \ $(NULL) 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))]; +} diff --git a/common/gvfsutils.h b/common/gvfsutils.h new file mode 100644 index 00000000..aa7faf5e --- /dev/null +++ b/common/gvfsutils.h @@ -0,0 +1,30 @@ +/* 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/>. + */ + +#ifndef __G_VFS_UTILS_H__ +#define __G_VFS_UTILS_H__ + +G_BEGIN_DECLS + +void gvfs_randomize_string (char *str, + int len); + +G_END_DECLS + +#endif /* __G_VFS_UTILS_H__ */ |