diff options
| author | Collin Funk <collin.funk1@gmail.com> | 2024-06-29 04:36:38 -0700 |
|---|---|---|
| committer | Pádraig Brady <P@draigBrady.com> | 2024-06-29 16:11:23 +0100 |
| commit | fe7208b90d617267826ccef114b911b7e0df407c (patch) | |
| tree | 2217bac773993e0029cf88b734d0efe9a299365c | |
| parent | 7cd51438192c2c18c17611494c54ed775be645f3 (diff) | |
| download | coreutils-fe7208b90d617267826ccef114b911b7e0df407c.tar.gz coreutils-fe7208b90d617267826ccef114b911b7e0df407c.zip | |
maint: prefer endian.h for byte order conversions
* bootstrap.conf (gnulib_modules): Remove byteswap. Add endian.
* src/cksum.c: Include endian.h instead of byteswap.h.
(SWAP): Remove macro.
(cksum_slice8): Use htobe32 instead of SWAP.
(output_crc): Likewise.
* src/sum.c: Include endian.h instead of byteswap.h.
(SWAP): Remove macro.
(output_bsd): Use htobe16 instead of SWAP.
(output_sysv): Use htobe16 instead of SWAP.
* .gitignore: Add /lib/endian.h.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | bootstrap.conf | 2 | ||||
| -rw-r--r-- | src/cksum.c | 14 | ||||
| -rw-r--r-- | src/sum.c | 12 |
4 files changed, 9 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore index 22d6b01df..407203dc3 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,7 @@ /lib/configmake.h /lib/ctype.h /lib/dirent.h +/lib/endian.h /lib/errno.h /lib/error.h /lib/fcntl.h diff --git a/bootstrap.conf b/bootstrap.conf index 43924c5b1..63bf192cc 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -47,7 +47,6 @@ gnulib_modules=" base64 btoc32 buffer-lcm - byteswap c-strcase c32iscntrl c32isspace @@ -78,6 +77,7 @@ gnulib_modules=" do-release-commit-and-tag dtoastr dup2 + endian environ error euidaccess diff --git a/src/cksum.c b/src/cksum.c index ca6775539..9909b14f5 100644 --- a/src/cksum.c +++ b/src/cksum.c @@ -37,15 +37,9 @@ #include <stdio.h> #include <sys/types.h> #include <stdint.h> +#include <endian.h> #include "system.h" -#include <byteswap.h> -#ifdef WORDS_BIGENDIAN -# define SWAP(n) (n) -#else -# define SWAP(n) bswap_32 (n) -#endif - #ifdef CRCTAB # define BIT(x) ((uint_fast32_t) 1 << (x)) @@ -189,8 +183,8 @@ cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out) while (bytes_read >= 8) { uint32_t first = *datap++, second = *datap++; - crc ^= SWAP (first); - second = SWAP (second); + crc ^= htobe32 (first); + second = htobe32 (second); crc = (crctab[7][(crc >> 24) & 0xFF] ^ crctab[6][(crc >> 16) & 0xFF] ^ crctab[5][(crc >> 8) & 0xFF] @@ -258,7 +252,7 @@ output_crc (char const *file, int binary_file, void const *digest, bool raw, if (raw) { /* Output in network byte order (big endian). */ - uint32_t out_int = SWAP (*(uint32_t *)digest); + uint32_t out_int = htobe32 (*(uint32_t *)digest); fwrite (&out_int, 1, 32/8, stdout); return; } @@ -22,17 +22,11 @@ #include <stdio.h> #include <sys/types.h> +#include <endian.h> #include "system.h" #include "human.h" #include "sum.h" -#include <byteswap.h> -#ifdef WORDS_BIGENDIAN -# define SWAP(n) (n) -#else -# define SWAP(n) bswap_16 (n) -#endif - /* Calculate the checksum and the size in bytes of stream STREAM. Return -1 on error, 0 on success. */ @@ -198,7 +192,7 @@ output_bsd (char const *file, int binary_file, void const *digest, { /* Output in network byte order (big endian). */ uint16_t out_int = *(int *)digest; - out_int = SWAP (out_int); + out_int = htobe16 (out_int); fwrite (&out_int, 1, 16/8, stdout); return; } @@ -223,7 +217,7 @@ output_sysv (char const *file, int binary_file, void const *digest, { /* Output in network byte order (big endian). */ uint16_t out_int = *(int *)digest; - out_int = SWAP (out_int); + out_int = htobe16 (out_int); fwrite (&out_int, 1, 16/8, stdout); return; } |
