Merge branch 'collectd-5.8'
[collectd.git] / src / daemon / common.c
index 76c7036..b5a1c98 100644 (file)
  *   Michał Mirosław <mirq-linux at rere.qmqm.pl>
 **/
 
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #include "collectd.h"
 
 #include "common.h"
 extern kstat_ctl_t *kc;
 #endif
 
+#if !defined(MSG_DONTWAIT)
+#if defined(MSG_NONBLOCK)
 /* AIX doesn't have MSG_DONTWAIT */
-#ifndef MSG_DONTWAIT
 #define MSG_DONTWAIT MSG_NONBLOCK
-#endif
+#else
+/* Windows doesn't have MSG_DONTWAIT or MSG_NONBLOCK */
+#define MSG_DONTWAIT 0
+#endif /* defined(MSG_NONBLOCK) */
+#endif /* !defined(MSG_DONTWAIT) */
 
-#if !HAVE_GETPWNAM_R
+#if !HAVE_GETPWNAM_R && defined(HAVE_GETPWNAM)
 static pthread_mutex_t getpwnam_r_lock = PTHREAD_MUTEX_INITIALIZER;
 #endif
 
@@ -338,6 +339,9 @@ int strjoin(char *buffer, size_t buffer_size, char **fields, size_t fields_num,
       buffer_req += sep_len;
     buffer_req += field_len;
 
+    if (buffer_size == 0)
+      continue;
+
     if ((i != 0) && (sep_len > 0)) {
       if (sep_len >= avail) {
         /* prevent subsequent iterations from writing to the
@@ -441,7 +445,7 @@ int strunescape(char *buf, size_t buf_len) {
     /* Move everything after the position one position to the left.
      * Add a null-byte as last character in the buffer. */
     memmove(buf + i + 1, buf + i + 2, buf_len - i - 2);
-    buf[buf_len - 1] = 0;
+    buf[buf_len - 1] = '\0';
   }
   return 0;
 } /* int strunescape */
@@ -1012,7 +1016,7 @@ int parse_value(const char *value_orig, value_t *ret_value, int ds_type) {
   value_len = strlen(value);
 
   while ((value_len > 0) && isspace((int)value[value_len - 1])) {
-    value[value_len - 1] = 0;
+    value[value_len - 1] = '\0';
     value_len--;
   }
 
@@ -1132,6 +1136,9 @@ int parse_value_file(char const *path, value_t *ret_value, int ds_type) {
 #if !HAVE_GETPWNAM_R
 int getpwnam_r(const char *name, struct passwd *pwbuf, char *buf, size_t buflen,
                struct passwd **pwbufp) {
+#ifndef HAVE_GETPWNAM
+  return -1;
+#else
   int status = 0;
   struct passwd *pw;
 
@@ -1174,6 +1181,7 @@ int getpwnam_r(const char *name, struct passwd *pwbuf, char *buf, size_t buflen,
   pthread_mutex_unlock(&getpwnam_r_lock);
 
   return status;
+#endif /* HAVE_GETPWNAM */
 } /* int getpwnam_r */
 #endif /* !HAVE_GETPWNAM_R */