env_attr.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * (C) Copyright 2012
  3. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef __ENV_ATTR_H__
  8. #define __ENV_ATTR_H__
  9. #define ENV_ATTR_LIST_DELIM ','
  10. #define ENV_ATTR_SEP ':'
  11. /*
  12. * env_attr_walk takes as input an "attr_list" that takes the form:
  13. * attributes = [^,:\s]*
  14. * entry = name[:attributes]
  15. * list = entry[,list]
  16. * It will call the "callback" function with the "name" and "attributes"
  17. * The callback may return a non-0 to abort the list walk.
  18. * This return value will be passed through to the caller.
  19. * 0 is returned on success.
  20. */
  21. int env_attr_walk(const char *attr_list,
  22. int (*callback)(const char *name, const char *attributes, void *priv),
  23. void *priv);
  24. /*
  25. * env_attr_lookup takes as input an "attr_list" with the same form as above.
  26. * It also takes as input a "name" to look for.
  27. * If the name is found in the list, it's value is copied into "attributes".
  28. * There is no protection on attributes being too small for the value.
  29. * It returns -1 if attributes is NULL, 1 if "name" is not found, 2 if
  30. * "attr_list" is NULL.
  31. * Returns 0 on success.
  32. */
  33. int env_attr_lookup(const char *attr_list, const char *name, char *attributes);
  34. #endif /* __ENV_ATTR_H__ */