lib/hashtable: remove superfluous check
[pandora-u-boot.git] / lib / hashtable.c
index f82f246..7c08f5c 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <errno.h>
+#include <log.h>
 #include <malloc.h>
 #include <sort.h>
 
@@ -109,8 +110,10 @@ int hcreate_r(size_t nel, struct hsearch_data *htab)
        }
 
        /* There is still another table active. Return with error. */
-       if (htab->table != NULL)
+       if (htab->table != NULL) {
+               __set_errno(EINVAL);
                return 0;
+       }
 
        /* Change nel to the first prime number not smaller as nel. */
        nel |= 1;               /* make odd */
@@ -123,8 +126,10 @@ int hcreate_r(size_t nel, struct hsearch_data *htab)
        /* allocate memory and zero out */
        htab->table = (struct env_entry_node *)calloc(htab->size + 1,
                                                sizeof(struct env_entry_node));
-       if (htab->table == NULL)
+       if (htab->table == NULL) {
+               __set_errno(ENOMEM);
                return 0;
+       }
 
        /* everything went alright */
        return 1;
@@ -319,8 +324,7 @@ int hsearch_r(struct env_entry item, enum env_action action,
                 */
                unsigned hval2;
 
-               if (htab->table[idx].used == USED_DELETED
-                   && !first_deleted)
+               if (htab->table[idx].used == USED_DELETED)
                        first_deleted = idx;
 
                ret = _compare_and_overwrite_entry(item, action, retval, htab,
@@ -605,7 +609,7 @@ static int match_entry(struct env_entry *ep, int flag, int argc,
 
 ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
                 char **resp, size_t size,
-                int argc, char * const argv[])
+                int argc, char *const argv[])
 {
        struct env_entry *list[htab->size];
        char *res, *p;
@@ -821,6 +825,10 @@ int himport_r(struct hsearch_data *htab,
        if (nvars)
                memcpy(localvars, vars, sizeof(vars[0]) * nvars);
 
+#if CONFIG_IS_ENABLED(ENV_APPEND)
+       flag |= H_NOCLEAR;
+#endif
+
        if ((flag & H_NOCLEAR) == 0 && !nvars) {
                /* Destroy old hash table if one exists */
                debug("Destroy Hash Table: %p table = %p\n", htab,
@@ -941,9 +949,12 @@ int himport_r(struct hsearch_data *htab,
                e.data = value;
 
                hsearch_r(e, ENV_ENTER, &rv, htab, flag);
-               if (rv == NULL)
+#if !CONFIG_IS_ENABLED(ENV_WRITEABLE_LIST)
+               if (rv == NULL) {
                        printf("himport_r: can't insert \"%s=%s\" into hash table\n",
                                name, value);
+               }
+#endif
 
                debug("INSERT: table %p, filled %d/%d rv %p ==> name=\"%s\" value=\"%s\"\n",
                        htab, htab->filled, htab->size,