]> git.ozlabs.org Git - ccan/blobdiff - ccan/strmap/strmap.h
strmap: add strmap_getn for non-terminated string search.
[ccan] / ccan / strmap / strmap.h
index 0b32e6befc0ca2974ad7304dd967e1c95fae75d3..8724c31dcbb20d2686cd33cbc39149209af7b767 100644 (file)
@@ -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.