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;
+ uintmax_t limit, seed_val;
struct test_rng *rng;
- char *end;
- errno = 0;
- seed = STRTOULL(seed_str, &end, 0);
- if (*end != 0) {
+ limit = (uintmax_t)0xffffffff;
+ limit |= (limit << 16 << 16);
+
+ if (!test_strtoumax(&seed_val, seed_str, limit)) {
fprintf(stderr, "%s: invalid seed\n", seed_str);
return NULL;
- } else if (errno != 0) {
- fprintf(stderr, "%s: invalid seed: %s\n",
- seed_str, strerror(errno));
- return NULL;
}
rng = malloc_nofail(sizeof *rng);