From 87c5c9ef0463e1288059b5f7bfc7dd4100cee2e9 Mon Sep 17 00:00:00 2001 From: "Glenn K. Lockwood" Date: Mon, 8 Oct 2018 13:47:28 -0700 Subject: [PATCH] compile correctly with -std=c99 This patch enables correct compilation on both MacOS and Linux using only POSIX.1-2008-compliant C with XSI extensions. Specifically, POSIX.1-2008 is the minimum version because we use strdup(3); explicit XSI is required to expose putenv from glibc. --- configure.ac | 11 +++++++++++ src/aiori-DUMMY.c | 2 ++ src/aiori-MMAP.c | 2 ++ src/aiori.c | 11 +++++++++++ src/ior.c | 29 ++++++++++++++++++++--------- src/mdtest.c | 8 +++++++- src/option.c | 1 + src/parse_options.c | 5 +++++ travis-test.sh | 2 +- 9 files changed, 60 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index a3c41b0..c28fb71 100755 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,17 @@ AM_INIT_AUTOMAKE([check-news dist-bzip2 gnu no-define foreign subdir-objects]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AM_MAINTAINER_MODE +# Check for system-specific stuff +case "${host_os}" in + *linux*) + ;; + *darwin*) + CPPFLAGS="${CPPFLAGS} -D_DARWIN_C_SOURCE" + ;; + *) + ;; +esac + # Checks for programs # We can't do anything without a working MPI diff --git a/src/aiori-DUMMY.c b/src/aiori-DUMMY.c index cfd920b..fd3b087 100755 --- a/src/aiori-DUMMY.c +++ b/src/aiori-DUMMY.c @@ -6,6 +6,8 @@ # include "config.h" #endif +#define _XOPEN_SOURCE 700 + #include #include #include diff --git a/src/aiori-MMAP.c b/src/aiori-MMAP.c index f812bdd..ed04357 100644 --- a/src/aiori-MMAP.c +++ b/src/aiori-MMAP.c @@ -11,6 +11,8 @@ # include "config.h" #endif +#define _XOPEN_SOURCE 700 + #include #include diff --git a/src/aiori.c b/src/aiori.c index 333f239..9c27386 100644 --- a/src/aiori.c +++ b/src/aiori.c @@ -12,8 +12,19 @@ * \******************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#define _XOPEN_SOURCE 700 + #include #include + +#if defined(HAVE_STRINGS_H) +#include +#endif + #include "aiori.h" #if defined(HAVE_SYS_STATVFS_H) diff --git a/src/ior.c b/src/ior.c index 66cca76..d383eb9 100755 --- a/src/ior.c +++ b/src/ior.c @@ -12,6 +12,8 @@ # include "config.h" #endif +#define _XOPEN_SOURCE 700 + #include #include #include @@ -20,6 +22,11 @@ #include #include #include + +#if defined(HAVE_STRINGS_H) +#include +#endif + #include /* struct stat */ #include @@ -458,12 +465,16 @@ static int CountErrors(IOR_param_t * test, int access, int errors) */ static void *aligned_buffer_alloc(size_t size) { - size_t pageSize; size_t pageMask; char *buf, *tmp; char *aligned; - pageSize = getpagesize(); +#ifdef HAVE_GETPAGESIZE + size_t pageSize = getpagesize(); +#else + long pageSize = sysconf(_SC_PAGESIZE); +#endif + pageMask = pageSize - 1; buf = malloc(size + pageSize + sizeof(void *)); if (buf == NULL) @@ -1410,7 +1421,7 @@ static void TestIoSys(IOR_test_t *test) /* random process offset reading */ if (params->reorderTasksRandom) { /* this should not intefere with randomOffset within a file because GetOffsetArrayRandom */ - /* seeds every random() call */ + /* seeds every rand() call */ int nodeoffset; unsigned int iseed0; nodeoffset = params->taskPerNodeOffset; @@ -1762,11 +1773,11 @@ static IOR_offset_t *GetOffsetArrayRandom(IOR_param_t * test, int pretendRank, /* set up seed for random() */ if (access == WRITE || access == READ) { - test->randomSeed = seed = random(); + test->randomSeed = seed = rand(); } else { seed = test->randomSeed; } - srandom(seed); + srand(seed); fileSize = test->blockSize * test->segmentCount; if (test->filePerProc == FALSE) { @@ -1778,7 +1789,7 @@ static IOR_offset_t *GetOffsetArrayRandom(IOR_param_t * test, int pretendRank, if (test->filePerProc == FALSE) { // this counts which process get how many transferes in // a shared file - if ((random() % test->numTasks) == pretendRank) { + if ((rand() % test->numTasks) == pretendRank) { offsets++; } } else { @@ -1800,9 +1811,9 @@ static IOR_offset_t *GetOffsetArrayRandom(IOR_param_t * test, int pretendRank, } } else { /* fill with offsets (pass 2) */ - srandom(seed); /* need same seed to get same transfers as counted in the beginning*/ + srand(seed); /* need same seed to get same transfers as counted in the beginning*/ for (i = 0; i < fileSize; i += test->transferSize) { - if ((random() % test->numTasks) == pretendRank) { + if ((rand() % test->numTasks) == pretendRank) { offsetArray[offsetCnt] = i; offsetCnt++; } @@ -1810,7 +1821,7 @@ static IOR_offset_t *GetOffsetArrayRandom(IOR_param_t * test, int pretendRank, } /* reorder array */ for (i = 0; i < offsets; i++) { - value = random() % offsets; + value = rand() % offsets; tmp = offsetArray[value]; offsetArray[value] = offsetArray[i]; offsetArray[i] = tmp; diff --git a/src/mdtest.c b/src/mdtest.c index 9d732a8..84f40c8 100644 --- a/src/mdtest.c +++ b/src/mdtest.c @@ -28,6 +28,7 @@ * $Date: 2013/11/27 17:05:31 $ * $Author: brettkettering $ */ +#define _XOPEN_SOURCE 700 #include #include @@ -59,6 +60,11 @@ #include #include + +#if HAVE_STRINGS_H +#include +#endif + #include #include #include @@ -1616,7 +1622,7 @@ void valid_tests() { FAIL("-c not compatible with -B"); } - if ( strcasecmp(backend_name, "POSIX") != 0 && strcasecmp(backend_name, "DUMMY") != 0) { + if (strcasecmp(backend_name, "POSIX") != 0 && strcasecmp(backend_name, "DUMMY") != 0) { FAIL("-a only supported interface is POSIX (and DUMMY) right now!"); } diff --git a/src/option.c b/src/option.c index 1e646af..5bd19fe 100644 --- a/src/option.c +++ b/src/option.c @@ -1,3 +1,4 @@ +#define _XOPEN_SOURCE 700 #include #include #include diff --git a/src/parse_options.c b/src/parse_options.c index 460dd52..546d0dc 100755 --- a/src/parse_options.c +++ b/src/parse_options.c @@ -16,11 +16,16 @@ #include "config.h" #endif +#define _XOPEN_SOURCE 700 + #include #include #include #include +#if defined(HAVE_STRINGS_H) +#include +#endif #include "utilities.h" #include "ior.h" diff --git a/travis-test.sh b/travis-test.sh index dfc1235..7bd84a0 100755 --- a/travis-test.sh +++ b/travis-test.sh @@ -5,7 +5,7 @@ # # These options will be passed directly to the autoconf configure script -CONFIGURE_OPTS="${CONFIGURE_OPTS:-""}" +CONFIGURE_OPTS="${CONFIGURE_OPTS:-"CFLAGS=-std=c99 --disable-silent-rules"}" BASE_DIR="$(cd "${0%/*}" && pwd)" if [ -z "$BASE_DIR" -o ! -d "$BASE_DIR" ]; then