]> git.draconx.ca Git - cdecl99.git/blobdiff - test/rng.c
Portability improvements for new random number generator.
[cdecl99.git] / test / rng.c
index 884d981767f9a09b3becef08f3506540adc516ec..d86b623233ba88abfc069404ba149be5f1b5e62b 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 #include <errno.h>
 #include <limits.h>
 #include <float.h>
@@ -71,6 +72,19 @@ static unsigned long long splitmix64(unsigned long long *state)
        return z ^ (z >> 31);
 }
 
+#if HAVE_STRTOULL
+#  define STRTOULL strtoull
+#elif HAVE___STRTOULL
+/* HP-UX 11 has __strtoull in <inttypes.h> */
+#  define STRTOULL __strtoull
+#else
+/*
+ * Just fall back to strtoul -- in the worst case we just lose the ability
+ * to set all 64 bits of the seed.
+ */
+#  define STRTOULL strtoul
+#endif
+
 struct test_rng *test_rng_alloc(const char *seed_str)
 {
        unsigned long long seed;
@@ -78,7 +92,7 @@ struct test_rng *test_rng_alloc(const char *seed_str)
        char *end;
 
        errno = 0;
-       seed = strtoull(seed_str, &end, 0);
+       seed = STRTOULL(seed_str, &end, 0);
        if (*end != 0) {
                fprintf(stderr, "%s: invalid seed\n", seed_str);
                return NULL;