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