Lines Matching +full:entry +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0+
25 * entry = name[:attributes]
26 * list = entry[,list]
29 int (*callback)(const char *name, const char *attributes, void *priv), in env_attr_walk() argument
32 const char *entry, *entry_end; in env_attr_walk() local
33 char *name, *attributes; in env_attr_walk() local
39 entry = attr_list; in env_attr_walk()
43 entry_end = strchr(entry, ENV_ATTR_LIST_DELIM); in env_attr_walk()
44 /* check if this is the last entry in the list */ in env_attr_walk()
46 int entry_len = strlen(entry); in env_attr_walk()
50 * allocate memory to copy the entry into since in env_attr_walk()
52 * white-space before calling the callback in env_attr_walk()
57 strcpy(entry_cpy, entry); in env_attr_walk()
59 return -ENOMEM; in env_attr_walk()
62 int entry_len = entry_end - entry; in env_attr_walk()
66 * allocate memory to copy the entry into since in env_attr_walk()
68 * white-space before calling the callback in env_attr_walk()
72 /* copy just this entry and null term */ in env_attr_walk()
73 strncpy(entry_cpy, entry, entry_len); in env_attr_walk()
76 return -ENOMEM; in env_attr_walk()
85 /* replace the ':' with '\0' to term name */ in env_attr_walk()
87 /* remove white-space from attributes */ in env_attr_walk()
90 /* remove white-space from name */ in env_attr_walk()
91 name = strim(entry_cpy); in env_attr_walk()
93 /* only call the callback if there is a name */ in env_attr_walk()
94 if (strlen(name) != 0) { in env_attr_walk()
97 retval = callback(name, attributes, priv); in env_attr_walk()
106 entry = entry_end + 1; in env_attr_walk()
119 static int regex_callback(const char *name, const char *attributes, void *priv) in regex_callback() argument
124 char regex[strlen(name) + 3]; in regex_callback()
127 sprintf(regex, "^%s$", name); in regex_callback()
131 if (slre_match(&slre, cbp->searched_for, in regex_callback()
132 strlen(cbp->searched_for), caps)) { in regex_callback()
133 free(cbp->regex); in regex_callback()
135 retval = -EINVAL; in regex_callback()
138 cbp->regex = malloc(strlen(regex) + 1); in regex_callback()
139 if (cbp->regex) { in regex_callback()
140 strcpy(cbp->regex, regex); in regex_callback()
142 retval = -ENOMEM; in regex_callback()
146 free(cbp->attributes); in regex_callback()
147 cbp->attributes = malloc(strlen(attributes) + 1); in regex_callback()
148 if (cbp->attributes) { in regex_callback()
149 strcpy(cbp->attributes, attributes); in regex_callback()
151 retval = -ENOMEM; in regex_callback()
152 free(cbp->regex); in regex_callback()
153 cbp->regex = NULL; in regex_callback()
159 retval = -EINVAL; in regex_callback()
166 * Retrieve the attributes string associated with a single name in the list
169 int env_attr_lookup(const char *attr_list, const char *name, char *attributes) in env_attr_lookup() argument
173 return -EINVAL; in env_attr_lookup()
176 return -EINVAL; in env_attr_lookup()
181 priv.searched_for = name; in env_attr_lookup()
195 return -ENOENT; /* not found in list */ in env_attr_lookup()
200 * Search for the last exactly matching name in an attribute list
226 prevch = match - 1; in reverse_name_search()
231 prevch--; in reverse_name_search()
240 prevch != searched - 1) in reverse_name_search()
256 * Retrieve the attributes string associated with a single name in the list
259 int env_attr_lookup(const char *attr_list, const char *name, char *attributes) in env_attr_lookup() argument
261 const char *entry = NULL; in env_attr_lookup() local
266 return -EINVAL; in env_attr_lookup()
269 return -EINVAL; in env_attr_lookup()
271 entry_len = reverse_name_search(attr_list, name, &entry); in env_attr_lookup()
272 if (entry != NULL) { in env_attr_lookup()
275 /* skip the name */ in env_attr_lookup()
276 entry += entry_len; in env_attr_lookup()
278 while (*entry == ' ') in env_attr_lookup()
279 entry++; in env_attr_lookup()
280 if (*entry != ENV_ATTR_SEP) in env_attr_lookup()
288 entry += 1; in env_attr_lookup()
290 while (*entry == ' ') in env_attr_lookup()
291 entry++; in env_attr_lookup()
293 delim = strpbrk(entry, delims); in env_attr_lookup()
295 len = strlen(entry); in env_attr_lookup()
297 len = delim - entry; in env_attr_lookup()
298 memcpy(attributes, entry, len); in env_attr_lookup()
307 return -ENOENT; in env_attr_lookup()