p9y: fix includes
[m6w6/libmemcached] / contrib / bin / memaslap / ms_setting.c
index 9d328ddcf62ae831908c57b89ffd0b91a908aeed..7cbdb53d30261a931315facef9e97ae5136ed0a8 100644 (file)
 #include <inttypes.h>
 #include <limits.h>
 #include <pwd.h>
-#include <strings.h>
+#if HAVE_STRINGS_H
+#  include <strings.h>
+#endif
 #include <sys/types.h>
-#include <unistd.h>
+#if HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
 
 #include "ms_setting.h"
 #include "ms_conn.h"
@@ -179,32 +183,28 @@ static void ms_get_serverlist(char *str) {
 /**
  * used to get the CPU count of the current system
  *
- * @return return the cpu count if get, else return EXIT_FAILURE
+ * @return return the cpu count if possible, else return 1
  */
 static uint32_t ms_get_cpu_count() {
-#ifdef HAVE__SC_NPROCESSORS_ONLN
-  return sysconf(_SC_NPROCESSORS_CONF);
-
-#else
-#  ifdef HAVE_CPU_SET_T
-  int cpu_count = 0;
+#ifdef HAVE_CPU_SET_T
+  unsigned cpu_count = 0;
   cpu_set_t cpu_set;
 
   sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set);
 
-  for (int i = 0; i < (sizeof(cpu_set_t) * 8); i++) {
+  for (unsigned i = 0; i < (sizeof(cpu_set_t) * 8); i++) {
     if (CPU_ISSET(i, &cpu_set)) {
       cpu_count++;
     }
   }
 
   return cpu_count;
-
-#  endif
+#elif defined HAVE__SC_NPROCESSORS_ONLN
+  return sysconf(_SC_NPROCESSORS_CONF);
 #endif
 
   /* the system with one cpu at least */
-  return EXIT_FAILURE;
+  return 1;
 } /* ms_get_cpu_count */
 
 /**