about summary refs log tree commit diff
path: root/src/libstddjb
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-12 03:54:29 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-12 03:54:29 +0000
commitb305bf616804db7176601bc2acd3495f0217e1c4 (patch)
tree872d15cd162204ec273199e7d0495bb163daa1b4 /src/libstddjb
parent4fa9aa58a926275c2db31a4cc98122e7883c714a (diff)
downloadskalibs-b305bf616804db7176601bc2acd3495f0217e1c4.tar.gz
skalibs-b305bf616804db7176601bc2acd3495f0217e1c4.tar.xz
skalibs-b305bf616804db7176601bc2acd3495f0217e1c4.zip
Add UINT??_BSWAP as constexp macro; rip off typedef uint?? bandaid
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb')
-rw-r--r--src/libstddjb/ntp_from_tain.c6
-rw-r--r--src/libstddjb/uint16_bswap.c3
-rw-r--r--src/libstddjb/uint32_bswap.c7
-rw-r--r--src/libstddjb/uint64_bswap.c10
4 files changed, 6 insertions, 20 deletions
diff --git a/src/libstddjb/ntp_from_tain.c b/src/libstddjb/ntp_from_tain.c
index 85a338a..5fc0a57 100644
--- a/src/libstddjb/ntp_from_tain.c
+++ b/src/libstddjb/ntp_from_tain.c
@@ -12,9 +12,9 @@ int ntp_from_tain (uint64_t *u, tain const *a)
   secs += NTP_OFFSET ;
   if (secs < TAI_MAGIC + 2147483648UL) goto ifail ;
   secs -= TAI_MAGIC ;
-  if (secs >= ((uint64)3 << 31)) goto ifail ;
-  secs &= (secs < ((uint64)1 << 32)) ? 0xFFFFFFFFUL : 0x7FFFFFFFUL ;
-  frac = ((uint64)a->nano << 32) / 1000000000UL ;
+  if (secs >= ((uint64_t)3 << 31)) goto ifail ;
+  secs &= (secs < ((uint64_t)1 << 32)) ? 0xFFFFFFFFUL : 0x7FFFFFFFUL ;
+  frac = ((uint64_t)a->nano << 32) / 1000000000UL ;
   *u = (secs << 32) + frac ;
   return 1 ;
  ifail:
diff --git a/src/libstddjb/uint16_bswap.c b/src/libstddjb/uint16_bswap.c
index 6ab96ed..9cc0df0 100644
--- a/src/libstddjb/uint16_bswap.c
+++ b/src/libstddjb/uint16_bswap.c
@@ -1,9 +1,8 @@
 /* ISC license. */
 
-#include <stdint.h>
 #include <skalibs/uint16.h>
 
 uint16_t uint16_bswap (uint16_t a)
 {
-  return (a & 0x00ffu) << 8 | (a & 0xff00u) >> 8 ;
+  return UINT16_BSWAP(a) ;
 }
diff --git a/src/libstddjb/uint32_bswap.c b/src/libstddjb/uint32_bswap.c
index b9dbcab..5348a5a 100644
--- a/src/libstddjb/uint32_bswap.c
+++ b/src/libstddjb/uint32_bswap.c
@@ -1,13 +1,8 @@
 /* ISC license. */
 
-#include <stdint.h>
 #include <skalibs/uint32.h>
 
 uint32_t uint32_bswap (uint32_t a)
 {
-  return
-   (a & 0x000000ffu) << 24 |
-   (a & 0x0000ff00u) << 8 |
-   (a & 0x00ff0000u) >> 8 |
-   (a & 0xff000000u) >> 24 ;
+  return UINT32_BSWAP(a) ;
 }
diff --git a/src/libstddjb/uint64_bswap.c b/src/libstddjb/uint64_bswap.c
index 3dfaf18..948d905 100644
--- a/src/libstddjb/uint64_bswap.c
+++ b/src/libstddjb/uint64_bswap.c
@@ -4,13 +4,5 @@
 
 uint64_t uint64_bswap (uint64_t a)
 {
-  return
-   (a & 0x00000000000000ffull) << 56 |
-   (a & 0x000000000000ff00ull) << 40 |
-   (a & 0x0000000000ff0000ull) << 24 |
-   (a & 0x00000000ff000000ull) << 8 |
-   (a & 0x000000ff00000000ull) >> 8 |
-   (a & 0x0000ff0000000000ull) >> 24 |
-   (a & 0x00ff000000000000ull) >> 40 |
-   (a & 0xff00000000000000ull) >> 56 ;
+  return UINT64_BSWAP(a) ;
 }