- if (last == NULL)
- /* start over */
- *next = ((char *)env_get_addr(0));
- else {
- *next = last;
-
- for (i = 0; env_get_char(i) != '\0'; i = n + 1) {
- for (n = i; env_get_char(n) != '\0'; ++n) {
- if (n >= CONFIG_ENV_SIZE) {
- /* XXX shouldn't we set *next = NULL?? */
- return 0;
- }
- }
-
- if (envmatch((uchar *)last, i) < 0)
- continue;
-
- /* try to get next name */
- i = n + 1;
- if (env_get_char(i) == '\0') {
- /* no more left */
- *next = NULL;
- return 0;
- }
-
- *next = ((char *)env_get_addr(i));
- return 0;
+ if (last == NULL) {
+ var = NULL;
+ i = 0;
+ } else {
+ var = strdup(last);
+ s = strchr(var, '=');
+ if (s != NULL)
+ *s = 0;
+ search.key = var;
+ i = hsearch_r(search, ENV_FIND, &match, &env_htab, 0);
+ if (i == 0) {
+ i = API_EINVAL;
+ goto done;