diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2015-02-16 14:57:25 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-02-16 14:57:25 +0100 |
commit | 787b67bc0603a71e645a04269db8309ab0977c94 (patch) | |
tree | e053a1a358a24a06511d13471118cc20e2dbd0d4 | |
parent | aff96bf116c07d0e513be84648e31fc0bcc34567 (diff) |
pkt: Use macro to generate pkt_put_u{8,16,32}
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | pkt.h | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -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 */ |