From 5dc2cc80ee62c8c7da2775b56e9ed5e1f30eb940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 2 Jun 2015 11:11:43 +0200 Subject: os_mon: Comply with C89 standard --- lib/os_mon/c_src/cpu_sup.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/os_mon/c_src/cpu_sup.c b/lib/os_mon/c_src/cpu_sup.c index b81a5cd1ad..9e217db105 100644 --- a/lib/os_mon/c_src/cpu_sup.c +++ b/lib/os_mon/c_src/cpu_sup.c @@ -543,36 +543,37 @@ static void util_measure(unsigned int **result_vec, int *result_sz) { #if defined(__FreeBSD__) #define EXIT_WITH(msg) (rich_error(msg, __FILE__, __LINE__)) +#define RICH_BUFLEN (213) /* left in error(char*) */ void rich_error(const char *reason, const char *file, const int line) { - const size_t buflen = 213; // left in error(char*) - char buf[buflen]; - snprintf(buf, buflen, "%s (%s:%i)", reason, file, line); + char buf[RICH_BUFLEN]; + snprintf(buf, RICH_BUFLEN, "%s (%s:%i)", reason, file, line); error(buf); } - +#undef RICH_BUFLEN static void util_measure(unsigned int **result_vec, int *result_sz) { int no_of_cpus; - getsysctl("hw.ncpu", &no_of_cpus, sizeof(int)); + size_t size_cpu_times; + unsigned long *cpu_times; + unsigned int *rv = NULL; + int i; - // Header constant CPUSTATES = #long values per cpu. - size_t size_cpu_times = sizeof(long) * CPUSTATES * no_of_cpus; - unsigned long *cpu_times = malloc(size_cpu_times); + getsysctl("hw.ncpu", &no_of_cpus, sizeof(int)); + /* Header constant CPUSTATES = #long values per cpu. */ + size_cpu_times = sizeof(long) * CPUSTATES * no_of_cpus; + cpu_times = malloc(size_cpu_times); if (!cpu_times) { EXIT_WITH("badalloc"); } getsysctl("kern.cp_times", cpu_times, size_cpu_times); - unsigned int *rv = NULL; - rv = *result_vec; rv[0] = no_of_cpus; rv[1] = CU_BSD_VALUES; ++rv; /* first value is number of cpus */ ++rv; /* second value is number of entries */ - int i; for (i = 0; i < no_of_cpus; ++i) { int offset = i * CPUSTATES; rv[ 0] = CU_CPU_ID; rv[ 1] = i; -- cgit v1.2.3