From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: Chris Kuhn <kuhnchris+passt@kuhnchris.eu>, lemmi <lemmi@nerd2nerd.org>
Subject: [PATCH 4/4] util: Carry own definition of __bswap_constant{16,32}
Date: Wed, 8 Mar 2023 08:35:16 +0100 [thread overview]
Message-ID: <20230308073516.2189680-5-sbrivio@redhat.com> (raw)
In-Reply-To: <20230308073516.2189680-1-sbrivio@redhat.com>
musl doesn't define those, use our own definition there. This is a
trivial implementation, similar to what's shipped by e.g. uClibc,
glibc, libiio.
Reported-by: Chris Kuhn <kuhnchris+github@kuhnchris.eu>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
util.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/util.h b/util.h
index 570094c..8367f51 100644
--- a/util.h
+++ b/util.h
@@ -88,6 +88,17 @@
#define MAC_ZERO ((uint8_t [ETH_ALEN]){ 0 })
#define MAC_IS_ZERO(addr) (!memcmp((addr), MAC_ZERO, ETH_ALEN))
+#ifndef __bswap_constant_16
+#define __bswap_constant_16(x) \
+ ((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
+#endif
+
+#ifndef __bswap_constant_32
+#define __bswap_constant_32(x) \
+ ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
+ (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
+#endif
+
#if __BYTE_ORDER == __BIG_ENDIAN
#define htons_constant(x) (x)
#define htonl_constant(x) (x)
--
@@ -88,6 +88,17 @@
#define MAC_ZERO ((uint8_t [ETH_ALEN]){ 0 })
#define MAC_IS_ZERO(addr) (!memcmp((addr), MAC_ZERO, ETH_ALEN))
+#ifndef __bswap_constant_16
+#define __bswap_constant_16(x) \
+ ((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
+#endif
+
+#ifndef __bswap_constant_32
+#define __bswap_constant_32(x) \
+ ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
+ (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
+#endif
+
#if __BYTE_ORDER == __BIG_ENDIAN
#define htons_constant(x) (x)
#define htonl_constant(x) (x)
--
2.39.2
next prev parent reply other threads:[~2023-03-08 7:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 7:35 [PATCH 0/4] Fix build against musl C library Stefano Brivio
2023-03-08 7:35 ` [PATCH 1/4] netlink: Use 8 KiB * netlink message header size as response buffer Stefano Brivio
2023-03-08 22:06 ` David Gibson
2023-03-08 7:35 ` [PATCH 2/4] conf, passt: Rename stderr to force_stderr Stefano Brivio
2023-03-08 22:10 ` David Gibson
2023-03-08 7:35 ` [PATCH 3/4] treewide: Fix header includes to build with musl Stefano Brivio
2023-03-08 22:11 ` David Gibson
2023-03-08 7:35 ` Stefano Brivio [this message]
2023-03-08 22:11 ` [PATCH 4/4] util: Carry own definition of __bswap_constant{16,32} David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230308073516.2189680-5-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=kuhnchris+passt@kuhnchris.eu \
--cc=lemmi@nerd2nerd.org \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).