addr = (char *)ep->data;
}
- if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
+ if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
+ 0, NULL) == 0) {
error("Environment import failed: errno = %d\n", errno);
return 1;
}
}
if (himport_r(&env_htab, (char *)default_environment,
- sizeof(default_environment), '\0', 0) == 0)
+ sizeof(default_environment), '\0', 0,
+ 0, NULL) == 0)
error("Environment import failed: errno = %d\n", errno);
gd->flags |= GD_FLG_ENV_READY;
}
}
- if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0)) {
+ if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0,
+ 0, NULL)) {
gd->flags |= GD_FLG_ENV_READY;
return 1;
}
const char __sep, char **__resp, size_t __size,
int argc, char * const argv[]);
+/*
+ * nvars: length of vars array
+ * vars: array of strings (variable names) to import (nvars == 0 means all)
+ */
extern int himport_r(struct hsearch_data *__htab,
const char *__env, size_t __size, const char __sep,
- int __flag);
+ int __flag, int nvars, char * const vars[]);
/* Flags for himport_r() */
#define H_NOCLEAR (1 << 0) /* do not clear hash table before importing */
* himport()
*/
+/* Check whether variable name is amongst vars[] */
+static int is_var_in_set(const char *name, int nvars, char * const vars[])
+{
+ int i = 0;
+
+ /* No variables specified means process all of them */
+ if (nvars == 0)
+ return 1;
+
+ for (i = 0; i < nvars; i++) {
+ if (!strcmp(name, vars[i]))
+ return 1;
+ }
+ debug("Skipping non-listed variable %s\n", name);
+
+ return 0;
+}
+
/*
* Import linearized data into hash table.
*
*/
int himport_r(struct hsearch_data *htab,
- const char *env, size_t size, const char sep, int flag)
+ const char *env, size_t size, const char sep, int flag,
+ int nvars, char * const vars[])
{
char *data, *sp, *dp, *name, *value;
*dp++ = '\0'; /* terminate name */
debug("DELETE CANDIDATE: \"%s\"\n", name);
+ if (!is_var_in_set(name, nvars, vars))
+ continue;
if (hdelete_r(name, htab) == 0)
debug("DELETE ERROR ##############################\n");
*sp++ = '\0'; /* terminate value */
++dp;
+ /* Skip variables which are not supposed to be processed */
+ if (!is_var_in_set(name, nvars, vars))
+ continue;
+
/* enter into hash table */
e.key = name;
e.data = value;