X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcommon.c;h=bcdf59aafdbd8a52a36579073f49ff2bf9b6c8f8;hb=4256c346a988d202b31442f6837d2672af80798b;hp=967a82af42c930fa01992df78774bf45d0f7945c;hpb=39d723f4cb1d50b7ebb90c3251f0ebabad576412;p=collectd.git diff --git a/src/common.c b/src/common.c index 967a82af..bcdf59aa 100644 --- a/src/common.c +++ b/src/common.c @@ -20,6 +20,10 @@ * Niki W. Waibel **/ +#if HAVE_CONFIG_H +# include "config.h" +#endif + #include "common.h" #include "plugin.h" @@ -500,7 +504,7 @@ unsigned long long ntohll (unsigned long long n) #else return (((unsigned long long) ntohl (n)) << 32) + ntohl (n >> 32); #endif -} +} /* unsigned long long ntohll */ unsigned long long htonll (unsigned long long n) { @@ -509,4 +513,41 @@ unsigned long long htonll (unsigned long long n) #else return (((unsigned long long) htonl (n)) << 32) + htonl (n >> 32); #endif -} +} /* unsigned long long htonll */ + +int format_name (char *ret, int ret_len, + const char *hostname, + const char *plugin, const char *plugin_instance, + const char *type, const char *type_instance) +{ + int status; + + assert (plugin != NULL); + assert (type != NULL); + + if ((plugin_instance == NULL) || (strlen (plugin_instance) == 0)) + { + if ((type_instance == NULL) || (strlen (type_instance) == 0)) + status = snprintf (ret, ret_len, "%s/%s/%s", + hostname, plugin, type); + else + status = snprintf (ret, ret_len, "%s/%s/%s-%s", + hostname, plugin, type, + type_instance); + } + else + { + if ((type_instance == NULL) || (strlen (type_instance) == 0)) + status = snprintf (ret, ret_len, "%s/%s-%s/%s", + hostname, plugin, plugin_instance, + type); + else + status = snprintf (ret, ret_len, "%s/%s-%s/%s-%s", + hostname, plugin, plugin_instance, + type, type_instance); + } + + if ((status < 1) || (status >= ret_len)) + return (-1); + return (0); +} /* int format_name */