#include "system.h"
#include "xstrtol.h"
#include "error.h"
+#include "getpagesize.h"
#include "human.h"
#include "inttostr.h"
#include "quotearg.h" /* For quotearg_colon */
size_t lim; /* Amount of data to try writing */
size_t soff; /* Offset into buffer for next write */
ssize_t ssize; /* Return value from write */
-#if ISAAC_WORDS > 1024
- word32 r[ISAAC_WORDS * 3]; /* Multiple of 4K and of pattern size */
-#else
- word32 r[1024 * 3]; /* Multiple of 4K and of pattern size */
-#endif
+ word32 *r; /* Fill pattern. */
+ size_t rsize = 3 * MAX (ISAAC_WORDS, 1024) * sizeof *r; /* Fill size. */
+ size_t ralign = lcm (getpagesize (), sizeof *r); /* Fill alignment. */
char pass_string[PASS_NAME_SIZE]; /* Name of current pass */
/* Printable previous offset into the file */
return -1;
}
+ r = alloca (rsize + ralign - 1);
+ r = ptr_align (r, ralign);
+
/* Constant fill patterns need only be set up once. */
if (type >= 0)
{
- lim = sizeof r;
+ lim = rsize;
if ((off_t) lim > size && size != -1)
{
lim = (size_t) size;
for (;;)
{
/* How much to write this time? */
- lim = sizeof r;
+ lim = rsize;
if ((off_t) lim > size - offset && size != -1)
{
if (size < offset)
break;
}
if (type < 0)
- fillrand (s, r, sizeof r, lim);
+ fillrand (s, r, rsize, lim);
/* Loop to retry partial writes. */
for (soff = 0; soff < lim; soff += ssize)
{