e.key = name;
e.data = NULL;
- ep = hsearch (e, FIND);
+ hsearch_r(e, FIND, &ep, &env_htab);
if (ep == NULL)
return 0;
len = printf ("%s=%s\n", ep->key, ep->data);
}
/* print whole list */
- len = hexport('\n', &res, 0);
+ len = hexport_r(&env_htab, '\n', &res, 0);
if (len > 0) {
puts(res);
*/
e.key = name;
e.data = NULL;
- ep = hsearch (e, FIND);
+ hsearch_r(e, FIND, &ep, &env_htab);
/* Check for console redirection */
if (strcmp(name,"stdin") == 0) {
/* Delete only ? */
if ((argc < 3) || argv[2] == NULL) {
- int rc = hdelete(name);
+ int rc = hdelete_r(name, &env_htab);
return !rc;
}
e.key = name;
e.data = value;
- ep = hsearch(e, ENTER);
+ hsearch_r(e, ENTER, &ep, &env_htab);
free(value);
if (!ep) {
printf("## Error inserting \"%s\" variable, errno=%d\n",
e.key = name;
e.data = NULL;
- ep = hsearch (e, FIND);
+ hsearch_r(e, FIND, &ep, &env_htab);
return (ep ? ep->data : NULL);
}
}
if (sep) { /* export as text file */
- len = hexport(sep, &addr, size);
+ len = hexport_r(&env_htab, sep, &addr, size);
if (len < 0) {
error("Cannot export environment: errno = %d\n",
errno);
else /* export as raw binary data */
res = addr;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n",
errno);
addr = (char *)ep->data;
}
- if (himport(addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
+ if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
error("Environment import failed: errno = %d\n", errno);
return 1;
}
"\0"
};
+struct hsearch_data env_htab;
+
static uchar env_get_char_init (int index)
{
uchar c;
puts("Using default environment\n\n");
}
- if (himport((char *)default_environment,
+ if (himport_r(&env_htab, (char *)default_environment,
sizeof(default_environment), '\0', 0) == 0) {
error("Environment import failed: errno = %d\n", errno);
}
}
}
- if (himport((char *)ep->data, ENV_SIZE, '\0', 0)) {
+ if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0)) {
gd->flags |= GD_FLG_ENV_READY;
return 1;
}
char *res;
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
BUG_ON(env_ptr != NULL);
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
}
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
goto done;
goto done;
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
goto done;
return 1;
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
return 1;
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
return 1;
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
int rcode = 0;
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
};
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
}
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
}
res = (char *)&env_new.data;
- len = hexport('\0', &res, ENV_SIZE);
+ len = hexport_r(&env_htab, '\0', &res, ENV_SIZE);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
goto done;
unsigned char data[ENV_SIZE]; /* Environment data */
} env_t;
+#ifndef DO_DEPS_ONLY
+
+#include <search.h>
+
+extern struct hsearch_data env_htab;
+
/* Function that returns a character from the environment */
unsigned char env_get_char (int);
/* Import from binary representation into hash table */
int env_import(const char *buf, int check);
+#endif
+
#endif /* _ENVIRONMENT_H_ */
#define __set_errno(val) do { errno = val; } while (0)
-/*
- * Prototype structure for a linked-list data structure.
- * This is the type used by the `insque' and `remque' functions.
- */
-
-/* For use with hsearch(3). */
-typedef int (*__compar_fn_t) (__const void *, __const void *);
-typedef __compar_fn_t comparison_fn_t;
-
/* Action which shall be performed in the call the hsearch. */
typedef enum {
FIND,
};
/* Create a new hashing table which will at most contain NEL elements. */
-extern int hcreate(size_t __nel);
extern int hcreate_r(size_t __nel, struct hsearch_data *__htab);
/* Destroy current internal hashing table. */
-extern void hdestroy(void);
extern void hdestroy_r(struct hsearch_data *__htab);
/*
* NULL. If ACTION is `ENTER' replace existing data (if any) with
* ITEM.data.
* */
-extern ENTRY *hsearch(ENTRY __item, ACTION __action);
extern int hsearch_r(ENTRY __item, ACTION __action, ENTRY ** __retval,
struct hsearch_data *__htab);
/* Search and delete entry matching ITEM.key in internal hash table. */
-extern int hdelete(const char *__key);
extern int hdelete_r(const char *__key, struct hsearch_data *__htab);
-extern ssize_t hexport(const char __sep, char **__resp, size_t __size);
extern ssize_t hexport_r(struct hsearch_data *__htab,
const char __sep, char **__resp, size_t __size);
-extern int himport(const char *__env, size_t __size, const char __sep,
- int __flag);
extern int himport_r(struct hsearch_data *__htab,
const char *__env, size_t __size, const char __sep,
int __flag);
-/* Flags for himport() / himport_r() */
+/* Flags for himport_r() */
#define H_NOCLEAR 1 /* do not clear hash table before importing */
#endif /* search.h */
* [Knuth] The Art of Computer Programming, part 3 (6.4)
*/
-/*
- * The non-reentrant version use a global space for storing the hash table.
- */
-static struct hsearch_data htab;
-
/*
* The reentrant version has no static variables to maintain the state.
* Instead the interface of all functions is extended to take an argument
return number % div != 0;
}
-int hcreate(size_t nel)
-{
- return hcreate_r(nel, &htab);
-}
-
/*
* Before using the hash table we must allocate memory for it.
* Test for an existing table are done. We allocate one element
* The contents of the table is zeroed, especially the field used
* becomes zero.
*/
+
int hcreate_r(size_t nel, struct hsearch_data *htab)
{
/* Test for correct arguments. */
/*
* hdestroy()
*/
-void hdestroy(void)
-{
- hdestroy_r(&htab);
-}
/*
* After using the hash table it has to be destroyed. The used memory can
* be freed and the local static variable can be marked as not used.
*/
+
void hdestroy_r(struct hsearch_data *htab)
{
int i;
* example for functions like hdelete().
*/
-ENTRY *hsearch(ENTRY item, ACTION action)
-{
- ENTRY *result;
-
- (void) hsearch_r(item, action, &result, &htab);
-
- return result;
-}
-
int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
struct hsearch_data *htab)
{
* do that.
*/
-int hdelete(const char *key)
-{
- return hdelete_r(key, &htab);
-}
-
int hdelete_r(const char *key, struct hsearch_data *htab)
{
ENTRY e, *ep;
* bytes in the string will be '\0'-padded.
*/
-ssize_t hexport(const char sep, char **resp, size_t size)
-{
- return hexport_r(&htab, sep, resp, size);
-}
-
static int cmpkey(const void *p1, const void *p2)
{
ENTRY *e1 = *(ENTRY **) p1;
* '\0' and '\n' have really been tested.
*/
-int himport(const char *env, size_t size, const char sep, int flag)
-{
- return himport_r(&htab, env, size, sep, flag);
-}
-
int himport_r(struct hsearch_data *htab,
const char *env, size_t size, const char sep, int flag)
{