aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2021-09-12 18:12:47 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2021-09-12 18:12:47 +0000
commit6aa4d33cce95c534665f3f8e057f13a69ab10835 (patch)
treecfb6f1e6a17b8751adf037ab86a1e50594e79fb4 /src
parent15a477c9f6730cd98e40bbdbb0511cdf3a3c4319 (diff)
downloadsg3_utils-6aa4d33cce95c534665f3f8e057f13a69ab10835.tar.gz
sg_dd: srand48_r() and mrand48_r() are GNU libc specific, put conditional in so non-reentrant version used otherwise
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@913 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src')
-rw-r--r--src/sg_dd.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/sg_dd.c b/src/sg_dd.c
index 26a4b4db..7c7823b7 100644
--- a/src/sg_dd.c
+++ b/src/sg_dd.c
@@ -70,7 +70,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "6.28 20210816";
+static const char * version_str = "6.29 20210906";
#define ME "sg_dd: "
@@ -176,6 +176,9 @@ static uint8_t * free_zeros_buff = NULL;
static int read_long_blk_inc = READ_LONG_DEF_BLK_INC;
static long seed;
+#ifdef HAVE_SRAND48_R /* gcc extension. N.B. non-reentrant version slower */
+static struct drand48_data drand;/* opaque, used by srand48_r and mrand48_r */
+#endif
static const char * proc_allow_dio = "/proc/scsi/sg/allow_dio";
@@ -2123,7 +2126,11 @@ main(int argc, char * argv[])
#endif
if (verbose > 1)
pr2serr("seed=%ld\n", seed);
+#ifdef HAVE_SRAND48_R
+ srand48_r(seed, &drand);
+#else
srand48(seed);
+#endif
} else if (iflag.zero) {
ccp = "<zero bytes>";
cc2p = "00";
@@ -2400,7 +2407,11 @@ main(int argc, char * argv[])
for (kk = 0; kk < blocks; ++kk, bp += blk_sz) {
for (j = 0; j < blk_sz; j += jbump) {
/* mrand48 takes uniformly from [-2^31, 2^31) */
+#ifdef HAVE_SRAND48_R
+ mrand48_r(&drand, &rn);
+#else
rn = mrand48();
+#endif
*((uint32_t *)(bp + j)) = (uint32_t)rn;
}
}