env_attr.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * (C) Copyright 2012
  3. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __ENV_ATTR_H__
  24. #define __ENV_ATTR_H__
  25. #define ENV_ATTR_LIST_DELIM ','
  26. #define ENV_ATTR_SEP ':'
  27. /*
  28. * env_attr_walk takes as input an "attr_list" that takes the form:
  29. * attributes = [^,:\s]*
  30. * entry = name[:attributes]
  31. * list = entry[,list]
  32. * It will call the "callback" function with the "name" and attribute as "value"
  33. * The callback may return a non-0 to abort the list walk.
  34. * This return value will be passed through to the caller.
  35. * 0 is returned on success.
  36. */
  37. extern int env_attr_walk(const char *attr_list,
  38. int (*callback)(const char *name, const char *value));
  39. /*
  40. * env_attr_lookup takes as input an "attr_list" with the same form as above.
  41. * It also takes as input a "name" to look for.
  42. * If the name is found in the list, it's value is copied into "attributes".
  43. * There is no protection on attributes being too small for the value.
  44. * It returns -1 if attributes is NULL, 1 if "name" is not found, 2 if
  45. * "attr_list" is NULL.
  46. * Returns 0 on success.
  47. */
  48. extern int env_attr_lookup(const char *attr_list, const char *name,
  49. char *attributes);
  50. #endif /* __ENV_ATTR_H__ */