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.
master
Glenn K. Lockwood 2018-10-08 13:47:28 -07:00
parent bd53ce959d
commit 87c5c9ef04
9 changed files with 60 additions and 11 deletions

View File

@ -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

View File

@ -6,6 +6,8 @@
# include "config.h"
#endif
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

View File

@ -11,6 +11,8 @@
# include "config.h"
#endif
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdlib.h>

View File

@ -12,8 +12,19 @@
*
\******************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <stdbool.h>
#if defined(HAVE_STRINGS_H)
#include <strings.h>
#endif
#include "aiori.h"
#if defined(HAVE_SYS_STATVFS_H)

View File

@ -12,6 +12,8 @@
# include "config.h"
#endif
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -20,6 +22,11 @@
#include <math.h>
#include <mpi.h>
#include <string.h>
#if defined(HAVE_STRINGS_H)
#include <strings.h>
#endif
#include <sys/stat.h> /* struct stat */
#include <time.h>
@ -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;

View File

@ -28,6 +28,7 @@
* $Date: 2013/11/27 17:05:31 $
* $Author: brettkettering $
*/
#define _XOPEN_SOURCE 700
#include <limits.h>
#include <math.h>
@ -59,6 +60,11 @@
#include <fcntl.h>
#include <string.h>
#if HAVE_STRINGS_H
#include <strings.h>
#endif
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
@ -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!");
}

View File

@ -1,3 +1,4 @@
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>

View File

@ -16,11 +16,16 @@
#include "config.h"
#endif
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#if defined(HAVE_STRINGS_H)
#include <strings.h>
#endif
#include "utilities.h"
#include "ior.h"

View File

@ -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