X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fbytestring%2Fbytestring.h;fp=ccan%2Fbytestring%2Fbytestring.h;h=bd525601eb3a71cb40c050838db1f76268b5530b;hp=63472fe24d6cdfd6e84802f6103b2658a610b098;hb=c06054cd124670216d147c2e0660aab3c3fa683c;hpb=40b45c4cfbf110a8e790366302ff43fa94dc8daa diff --git a/ccan/bytestring/bytestring.h b/ccan/bytestring/bytestring.h index 63472fe2..bd525601 100644 --- a/ccan/bytestring/bytestring.h +++ b/ccan/bytestring/bytestring.h @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -80,4 +81,18 @@ static inline bool bytestring_eq(struct bytestring a, struct bytestring b) && (memcmp(a.ptr, b.ptr, a.len) == 0); } +/** + * bytestring_byte - get a byte from a bytestring + * @s: bytestring + * @n: index + * + * Return the @n-th byte from @s. Aborts (via assert) if @n is out of + * range for the length of @s. + */ +static inline char bytestring_byte(struct bytestring s, size_t n) +{ + assert(n < s.len); + return s.ptr[n]; +} + #endif /* CCAN_BYTESTRING_H_ */