X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fstrmap%2Fstrmap.h;fp=ccan%2Fstrmap%2Fstrmap.h;h=8724c31dcbb20d2686cd33cbc39149209af7b767;hb=d99e02dc8ae052b044ac255b1ec9ac76655a73c7;hp=0b32e6befc0ca2974ad7304dd967e1c95fae75d3;hpb=b737dbc2ba48b51f68437d0a8b7f7a4816da110a;p=ccan diff --git a/ccan/strmap/strmap.h b/ccan/strmap/strmap.h index 0b32e6be..8724c31d 100644 --- a/ccan/strmap/strmap.h +++ b/ccan/strmap/strmap.h @@ -72,7 +72,7 @@ static inline bool strmap_empty_(const struct strmap *map) /** * strmap_get - get a value from a string map * @map: the typed strmap to search. - * @member: the string to search for. + * @member: the string to search for (nul terminated) * * Returns the value, or NULL if it isn't in the map (and sets errno = ENOENT). * @@ -85,6 +85,23 @@ static inline bool strmap_empty_(const struct strmap *map) tcon_cast((map), canary, strmap_get_(tcon_unwrap(map), (member))) void *strmap_get_(const struct strmap *map, const char *member); +/** + * strmap_getn - get a value from a string map + * @map: the typed strmap to search. + * @member: the string to search for. + * @memberlen: the length of @member. + * + * Returns the value, or NULL if it isn't in the map (and sets errno = ENOENT). + * + * Example: + * val = strmap_getn(&map, "hello", 5); + * if (val) + * printf("hello => %i\n", *val); + */ +#define strmap_getn(map, member, n) \ + tcon_cast((map), canary, strmap_getn_(tcon_unwrap(map), (member), (n))) +void *strmap_getn_(const struct strmap *map, const char *member, size_t n); + /** * strmap_add - place a member in the string map. * @map: the typed strmap to add to.