diff options
Diffstat (limited to 'lib/util/randsysrandom.c')
-rw-r--r-- | lib/util/randsysrandom.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/util/randsysrandom.c b/lib/util/randsysrandom.c new file mode 100644 index 00000000..f26bb18d --- /dev/null +++ b/lib/util/randsysrandom.c @@ -0,0 +1,45 @@ +/* Implementation note: Mingw/Windows does not provide POSIX 'random', so + netpbm/pm_config.h makes that a macro for POSIX 'rand' on that platform +*/ + +#define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */ +#define _XOPEN_SOURCE 500 /* Make sure random() is in stdlib.h */ +#define _BSD_SOURCE /* Make sure random() is in stdlib.h */ + +#include <stdlib.h> + +#include "netpbm/pm_config.h" +#include "netpbm/rand.h" + +static void +vinit(struct pm_randSt * const randStP) { + + randStP->max = RAND_MAX; + randStP->stateP = NULL; +} + + + +static void +vsrand(struct pm_randSt * const randStP, + unsigned int const seed) { + + srandom(seed); +} + + + +static unsigned long int +vrand(struct pm_randSt * const randStP) { + + return random(); +} + + +struct pm_rand_vtable const pm_randsysrandom_vtable = { + &vinit, + &vsrand, + &vrand +}; + + |