#ifndef COLLECTD_H
#define COLLECTD_H
-#include <stdlib.h>
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#if STDC_HEADERS
+#include <stdlib.h>
+#include <stddef.h>
+#else
+# if HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
+#endif
+#if HAVE_STRING_H
+# if !STDC_HEADERS && HAVE_MEMORY_H
+# include <memory.h>
+# endif
+# include <string.h>
+#endif
+#if HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <sys/wait.h>
#include <signal.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <syslog.h>
#include <limits.h>
#include <time.h>
-#include "config.h"
-
#ifndef HAVE_RRD_H
#undef HAVE_LIBRRD
#endif