]> diplodocus.org Git - nmh/blobdiff - sbr/m_rand.c
new.c: Order two return statements to match comment.
[nmh] / sbr / m_rand.c
index 4d24888639b82bbc645e02897f198c498c8252f2..3227aef9690088c61d7f5152d400615cbc39e951 100644 (file)
@@ -1,21 +1,26 @@
-/*
- * m_rand -- provides pseudorandom bytes
+/* m_rand.c -- provides pseudorandom bytes
  *
  * This code is Copyright (c) 2012, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
-#include <stdlib.h>  /* for abs(), srand(), rand() */
+#include <stdlib.h>  /* for abs(), srand(), rand(), arc4random() */
 #include <stdio.h>   /* for fopen(), fread(), fclose() */
 #include <unistd.h>  /* for getpid() */
 #include <time.h>    /* for time() */
 
+#include <config.h>
+#include "m_rand.h"
+
+#if !HAVE_ARC4RANDOM
 static int seeded = 0;
+#endif
 
 
 int
 m_rand (unsigned char *buf, size_t n) {
+#if !HAVE_ARC4RANDOM
   if (! seeded) {
     FILE *devurandom;
     unsigned int seed;
@@ -46,6 +51,9 @@ m_rand (unsigned char *buf, size_t n) {
       *buf++ = *rndp++;
     }
   }
+#else
+  arc4random_buf(buf, n);
+#endif
 
   return 0;
 }