strlist.h 978 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef STRLIST_H_
  2. #define STRLIST_H_
  3. #include <linux/rbtree.h>
  4. #include <stdbool.h>
  5. struct str_node {
  6. struct rb_node rb_node;
  7. const char *s;
  8. };
  9. struct strlist {
  10. struct rb_root entries;
  11. unsigned int nr_entries;
  12. bool dupstr;
  13. };
  14. struct strlist *strlist__new(bool dupstr, const char *slist);
  15. void strlist__delete(struct strlist *self);
  16. void strlist__remove(struct strlist *self, struct str_node *sn);
  17. int strlist__load(struct strlist *self, const char *filename);
  18. int strlist__add(struct strlist *self, const char *str);
  19. struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
  20. bool strlist__has_entry(struct strlist *self, const char *entry);
  21. static inline bool strlist__empty(const struct strlist *self)
  22. {
  23. return self->nr_entries == 0;
  24. }
  25. static inline unsigned int strlist__nr_entries(const struct strlist *self)
  26. {
  27. return self->nr_entries;
  28. }
  29. int strlist__parse_list(struct strlist *self, const char *s);
  30. #endif /* STRLIST_H_ */