summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a795179)
raw | patch | inline | side by side (parent: a795179)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 27 Mar 2007 15:23:51 +0000 (17:23 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 27 Mar 2007 15:23:51 +0000 (17:23 +0200) |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 967a82af42c930fa01992df78774bf45d0f7945c..6521a58bd1a07a376fda133faed70f549e122ed3 100644 (file)
--- a/src/common.c
+++ b/src/common.c
#else
return (((unsigned long long) ntohl (n)) << 32) + ntohl (n >> 32);
#endif
-}
+} /* unsigned long long ntohll */
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 */
diff --git a/src/common.h b/src/common.h
index 310aa8a5ca2f1a4458c127aad58e8857d7d57c90..6c097f6c0ad3e454e7b288508b730e8102108d01 100644 (file)
--- a/src/common.h
+++ b/src/common.h
unsigned long long ntohll (unsigned long long n);
unsigned long long htonll (unsigned long long n);
+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);
+#define FORMAT_VL(ret, ret_len, vl, ds) \
+ format_name (ret, ret_len, (vl)->host, (vl)->plugin, (vl)->plugin_instance, \
+ (ds)->type, (vl)->type_instance)
+
#endif /* COMMON_H */