diff options
author | Jim Meyering <jim@meyering.net> | 1999-07-24 09:36:29 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-07-24 09:36:29 +0000 |
commit | 7b5a5af07f4289bebabb4a176fc09a6f4ba6a7ab (patch) | |
tree | 9317eda84ae60b7d0a9781d10cbe2bd16a24dbf2 | |
parent | c4731cc3f0bf26b06c26f24a429cca4ef749faba (diff) | |
download | coreutils-7b5a5af07f4289bebabb4a176fc09a6f4ba6a7ab.tar.xz |
(PTR_ALIGN, ROUND_UP_OFFSET): New macros.
(dd_copy): Use those to page-align both the input and output buffers.
-rw-r--r-- | src/dd.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -46,7 +46,9 @@ # define SIGINFO SIGUSR1 #endif -#define ROUND_UP_TO_MODULUS(X, M) (X + M - 1 - ((X + M - 1) % M)) +#define ROUND_UP_OFFSET(X, M) ((M) - 1 - (((X) + (M) - 1) % (M))) +#define PTR_ALIGN(Ptr, M) ((Ptr) \ + + ROUND_UP_OFFSET ((char *)(Ptr) - (char *)0, (M))) #define max(a, b) ((a) > (b) ? (a) : (b)) #define output_char(c) \ @@ -864,22 +866,24 @@ dd_copy (void) the input buffer; thus we allocate 2 pages of slop in the real buffer. 8k above the blocksize shouldn't bother anyone. */ - real_buf = (unsigned char *) xmalloc (input_blocksize + 2 * SWAB_ALIGN_OFFSET + 2 * page_size - 1); ibuf = real_buf; ibuf += SWAB_ALIGN_OFFSET; /* allow space for swab */ - /* FIXME: Rather than using uintmax_t here (uintmax_t is necessary on systems - where (sizeof void* > sizeof unsigned long), write a configure-time test - to determine the smallest unsigned integer type that can hold a pointer. */ - ibuf = (unsigned char *) ROUND_UP_TO_MODULUS ((uintmax_t) ibuf, page_size); + ibuf = PTR_ALIGN (ibuf, page_size); if (conversions_mask & C_TWOBUFS) - obuf = (unsigned char *) xmalloc (output_blocksize); + { + /* Page-align the output buffer, too. */ + obuf = (unsigned char *) xmalloc (output_blocksize + page_size - 1); + obuf = PTR_ALIGN (obuf, page_size); + } else - obuf = ibuf; + { + obuf = ibuf; + } if (skip_records != 0) skip (STDIN_FILENO, input_file, skip_records, input_blocksize, ibuf); |