From 3f773258bd736700a60dbb67a1f149b98666449b Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Mon, 11 Apr 2016 16:07:27 -0600 Subject: [PATCH] Corrected an issue with hashmap and missing random() function on Windows using Visual Studio 2013 --- CMakeLists.txt | 1 + config.h.cmake.in | 1 + configure.ac | 2 +- libsrc/nc_hashmap.c | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a356c23bb..6b72b2ba2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1177,6 +1177,7 @@ CHECK_FUNCTION_EXISTS(strtoull HAVE_STROULL) CHECK_FUNCTION_EXISTS(strstr HAVE_STRSTR) CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP) CHECK_FUNCTION_EXISTS(rand HAVE_RAND) +CHECK_FUNCTION_EXISTS(random HAVE_RANDOM) CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY) CHECK_FUNCTION_EXISTS(fsync HAVE_FSYNC) CHECK_FUNCTION_EXISTS(MPI_Comm_f2C HAVE_MPI_COMM_F2C) diff --git a/config.h.cmake.in b/config.h.cmake.in index b9c8221ed..b07b6a566 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -272,6 +272,7 @@ are set when opening a binary file on Windows. */ #cmakedefine HAVE_STRSTR #cmakedefine HAVE_MKSTEMP #cmakedefine HAVE_RAND +#cmakedefine HAVE_RANDOM #cmakedefine HAVE_GETTIMEOFDAY #cmakedefine HAVE_MPI_COMM_F2C #cmakedefine HAVE_MEMMOVE diff --git a/configure.ac b/configure.ac index eadbf6e1d..48e8145e8 100644 --- a/configure.ac +++ b/configure.ac @@ -750,7 +750,7 @@ AC_HEADER_STDBOOL # Check for these functions... AC_CHECK_FUNCS([strlcat strerror snprintf strchr strrchr strcat strcpy \ strdup strcasecmp strtod strtoll strtoull strstr \ - mkstemp rand memcmp \ + mkstemp rand random memcmp \ getrlimit gettimeofday fsync MPI_Comm_f2c]) # Does the user want to use NC_DISKLESS? diff --git a/libsrc/nc_hashmap.c b/libsrc/nc_hashmap.c index 14cd77f58..e8242549e 100644 --- a/libsrc/nc_hashmap.c +++ b/libsrc/nc_hashmap.c @@ -35,7 +35,11 @@ static int isPrime(unsigned long val) for (i = 9; i--;) { +#ifdef HAVE_RANDOM unsigned long a = ((unsigned long)random() % (val-4)) + 2; +#else + unsigned long a = ((unsigned long)rand() % (val - 4)) + 2; +#endif unsigned long p = 1; unsigned long exp = val-1; while (exp)