From 86477f342663bfcc3e87a7746d405f5c079b6d86 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 17 May 2016 20:21:06 +0200 Subject: os_mon: Fix compile error on FreeBSD implicit declaration of function 'EXIT_WITH' Move code chunk up a bit to #define EXIT_WITH before it's used. --- lib/os_mon/c_src/cpu_sup.c | 57 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'lib/os_mon') diff --git a/lib/os_mon/c_src/cpu_sup.c b/lib/os_mon/c_src/cpu_sup.c index 353c7e674e..17ef48c26e 100644 --- a/lib/os_mon/c_src/cpu_sup.c +++ b/lib/os_mon/c_src/cpu_sup.c @@ -602,6 +602,35 @@ static void util_measure(unsigned int **result_vec, int *result_sz) { } #endif +/* ---------------------------- * + * Utils for OSX and FreeBSD * + * ---------------------------- */ + +#if (defined(__APPLE__) && defined(__MACH__)) || 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) { + char buf[RICH_BUFLEN]; + snprintf(buf, RICH_BUFLEN, "%s (%s:%i)", reason, file, line); + error(buf); +} +#undef RICH_BUFLEN + +void getsysctl(const char *name, void *ptr, size_t len) +{ + size_t gotlen = len; + if (sysctlbyname(name, ptr, &gotlen, NULL, 0) != 0) { + EXIT_WITH("sysctlbyname failed"); + } + if (gotlen != len) { + EXIT_WITH("sysctlbyname: unexpected length"); + } +} +#endif + + /* ---------------------------- * * FreeBSD stat functions * * ---------------------------- */ @@ -645,34 +674,6 @@ static void util_measure(unsigned int **result_vec, int *result_sz) { } #endif -/* ---------------------------- * - * Utils for OSX and FreeBSD * - * ---------------------------- */ - -#if (defined(__APPLE__) && defined(__MACH__)) || 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) { - char buf[RICH_BUFLEN]; - snprintf(buf, RICH_BUFLEN, "%s (%s:%i)", reason, file, line); - error(buf); -} -#undef RICH_BUFLEN - -void getsysctl(const char *name, void *ptr, size_t len) -{ - size_t gotlen = len; - if (sysctlbyname(name, ptr, &gotlen, NULL, 0) != 0) { - EXIT_WITH("sysctlbyname failed"); - } - if (gotlen != len) { - EXIT_WITH("sysctlbyname: unexpected length"); - } -} -#endif - /* ---------------------------- * * Generic functions * -- cgit v1.2.3