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