summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 39dccb0)
raw | patch | inline | side by side (parent: 39dccb0)
author | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Fri, 3 Feb 2012 08:57:53 +0000 (09:57 +0100) | ||
committer | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Fri, 3 Feb 2012 08:57:53 +0000 (09:57 +0100) |
prefix and postfix need to be set to an empty string when
they are null since they are used in format strings.
swap_chars return value is never used and could never be
negative, switch to a void prototype instead.
they are null since they are used in format strings.
swap_chars return value is never used and could never be
negative, switch to a void prototype instead.
src/write_graphite.c | patch | blob | history |
diff --git a/src/write_graphite.c b/src/write_graphite.c
index 9e96198d6951c4eb64f469b4a28e083fe3950a07..bafe6ac256662872e05857c63790e77a6bcdfecd 100644 (file)
--- a/src/write_graphite.c
+++ b/src/write_graphite.c
return (0);
}
-static int swap_chars (char *dst, const char *src,
+static void swap_chars (char *dst, const char *src,
const char from, const char to)
{
size_t i;
- int reps = 0;
-
for (i = 0; i < strlen(src) ; i++)
{
if (src[i] == from)
- {
dst[i] = to;
- ++reps;
- }
else
dst[i] = src[i];
}
dst[i] = '\0';
-
- return reps;
}
static int wg_format_name (char *ret, int ret_len,
assert (plugin != NULL);
assert (type != NULL);
+ if (prefix == NULL)
+ prefix = "";
+
+ if (postfix == NULL)
+ postfix = "";
+
if ((n_hostname = malloc(strlen(hostname)+1)) == NULL)
{
ERROR ("Unable to allocate memory for normalized hostname buffer");
return (-1);
}
- if (swap_chars(n_hostname, hostname, '.', dotchar) == -1)
- {
- ERROR ("Unable to normalize hostname");
- return (-1);
- }
-
- if (swap_chars(n_plugin, plugin, ' ', '_') == -1)
- {
- ERROR ("Unable to normalize plugin");
- return (-1);
- }
-
- if (swap_chars(n_type, type, ' ', '_') == -1)
- {
- ERROR ("Unable to normalize type");
- return (-1);
- }
+ swap_chars(n_hostname, hostname, '.', dotchar);
+ swap_chars(n_plugin, plugin, ' ', '_');
+ swap_chars(n_type, type, ' ', '_');
if (type_instance != NULL && type_instance[0] != '\0')
{
ERROR ("Unable to allocate memory for normalized datasource name buffer");
return (-1);
}
- if (swap_chars(n_type_instance, type_instance, '.', dotchar) == -1)
- {
- ERROR ("Unable to normalize datasource name");
- return (-1);
- }
- if (swap_chars(n_type_instance, type_instance, ' ', '_') == -1)
- {
- ERROR ("Unable to normalize datasource name");
- return (-1);
- }
+ swap_chars(n_type_instance, type_instance, '.', dotchar);
+ swap_chars(n_type_instance, type_instance, ' ', '_');
}
if (plugin_instance != NULL && plugin_instance[0] != '\0')
ERROR ("Unable to allocate memory for normalized plugin instance buffer");
return (-1);
}
- if (swap_chars(n_plugin_instance, plugin_instance, ' ', '_') == -1)
- {
- ERROR ("Unable to normalize datasource name");
- return (-1);
- }
+ swap_chars(n_plugin_instance, plugin_instance, ' ', '_');
}
if ((n_plugin_instance == NULL) || (n_plugin_instance[0] == '\0'))