summaryrefslogtreecommitdiff
path: root/pkt.h
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-02-16 14:57:25 +0100
committerTobias Klauser <tklauser@distanz.ch>2015-02-16 14:57:25 +0100
commit787b67bc0603a71e645a04269db8309ab0977c94 (patch)
treee053a1a358a24a06511d13471118cc20e2dbd0d4 /pkt.h
parentaff96bf116c07d0e513be84648e31fc0bcc34567 (diff)
pkt: Use macro to generate pkt_put_u{8,16,32}
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'pkt.h')
-rw-r--r--pkt.h17
1 files changed, 8 insertions, 9 deletions
diff --git a/pkt.h b/pkt.h
index cd08a50..b043685 100644
--- a/pkt.h
+++ b/pkt.h
@@ -90,16 +90,15 @@ static inline uint8_t *pkt_put(struct pkt *p, size_t len)
return data;
}
-static inline void pkt_put_u16(struct pkt *p, uint16_t val)
-{
- uint16_t *data = (uint16_t *)pkt_put(p, sizeof(val));
- *data = val;
+#define DEFINE_PKT_PUT(__bitwidth) \
+static inline void pkt_put_u##__bitwidth(struct pkt *p, uint##__bitwidth##_t val) \
+{ \
+ uint##__bitwidth##_t *data = (uint##__bitwidth##_t *)pkt_put(p, sizeof(val)); \
+ *data = val; \
}
-static inline void pkt_put_u32(struct pkt *p, uint32_t val)
-{
- uint32_t *data = (uint32_t *)pkt_put(p, sizeof(val));
- *data = val;
-}
+DEFINE_PKT_PUT(8)
+DEFINE_PKT_PUT(16)
+DEFINE_PKT_PUT(32)
#endif /* PKT_H */