diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-11-13 22:31:18 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-11-14 21:31:43 -0800 |
| commit | eb328da56c3fc7167b536dcb206df0abb0f4a9b9 (patch) | |
| tree | c92e3dd3db6a0f1b0efc6a027e7e4db6442068f0 /tests/testutil.c | |
| parent | 7c1ff5ed1e48af413494b9070cccf79f3858b749 (diff) | |
| download | nng-eb328da56c3fc7167b536dcb206df0abb0f4a9b9.tar.gz nng-eb328da56c3fc7167b536dcb206df0abb0f4a9b9.tar.bz2 nng-eb328da56c3fc7167b536dcb206df0abb0f4a9b9.zip | |
fixes #1087 CMakeLists structural improvements desired
This doesn't modularize all the tests yet, but it goes a long way
in the right direction.
Diffstat (limited to 'tests/testutil.c')
| -rw-r--r-- | tests/testutil.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/tests/testutil.c b/tests/testutil.c index ce9978ce..ea8386b1 100644 --- a/tests/testutil.c +++ b/tests/testutil.c @@ -114,22 +114,30 @@ testutil_pollfd(int fd) return (false); } +bool +testutil_is_little_endian(void) +{ + uint16_t num = 0x1; + uint8_t *ptr = (uint8_t *) (void *) (&num); + return (ptr[0] == 1); +} + uint16_t testutil_htons(uint16_t in) { -#ifdef NNG_LITTLE_ENDIAN - in = ((in >> 8u) & 0xffu) | ((in & 0xffu) << 8u); -#endif + if (testutil_is_little_endian()) { + in = ((in / 0x100) + ((in % 0x100) * 0x100)); + } return (in); } uint32_t testutil_htonl(uint32_t in) { -#ifdef NNG_LITTLE_ENDIAN - in = ((in >> 24u) & 0xffu) | ((in >> 8u) & 0xff00u) | - ((in << 8u) & 0xff0000u) | ((in << 24u) & 0xff000000u); -#endif + if (testutil_is_little_endian()) { + in = ((in >> 24u) & 0xffu) | ((in >> 8u) & 0xff00u) | + ((in << 8u) & 0xff0000u) | ((in << 24u) & 0xff000000u); + } return (in); } |
