From 787b67bc0603a71e645a04269db8309ab0977c94 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 16 Feb 2015 14:57:25 +0100 Subject: pkt: Use macro to generate pkt_put_u{8,16,32} Signed-off-by: Tobias Klauser --- pkt.h | 17 ++++++++--------- 1 file 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 */ -- cgit v1.2.3-54-g00ecf