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