powerpc/85xx: Refactor some defines out of corenet_ds.h
[platform/kernel/u-boot.git] / lib / hashtable.c
index 92eaa38..026dbca 100644 (file)
@@ -155,7 +155,7 @@ void hdestroy_r(struct hsearch_data *htab)
                if (htab->table[i].used > 0) {
                        ENTRY *ep = &htab->table[i].entry;
 
-                       free(ep->key);
+                       free((void *)ep->key);
                        free(ep->data);
                }
        }
@@ -202,6 +202,29 @@ void hdestroy_r(struct hsearch_data *htab)
  *   example for functions like hdelete().
  */
 
+/*
+ * hstrstr_r - return index to entry whose key and/or data contains match
+ */
+int hstrstr_r(const char *match, int last_idx, ENTRY ** retval,
+             struct hsearch_data *htab)
+{
+       unsigned int idx;
+
+       for (idx = last_idx + 1; idx < htab->size; ++idx) {
+               if (htab->table[idx].used <= 0)
+                       continue;
+               if (strstr(htab->table[idx].entry.key, match) ||
+                   strstr(htab->table[idx].entry.data, match)) {
+                       *retval = &htab->table[idx].entry;
+                       return idx;
+               }
+       }
+
+       __set_errno(ESRCH);
+       *retval = NULL;
+       return 0;
+}
+
 int hmatch_r(const char *match, int last_idx, ENTRY ** retval,
             struct hsearch_data *htab)
 {
@@ -393,7 +416,7 @@ int hdelete_r(const char *key, struct hsearch_data *htab)
        /* free used ENTRY */
        debug("hdelete: DELETING key \"%s\"\n", key);
 
-       free(ep->key);
+       free((void *)ep->key);
        free(ep->data);
        htab->table[idx].used = -1;
 
@@ -541,7 +564,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep,
         * export sorted list of result data
         */
        for (i = 0, p = res; i < n; ++i) {
-               char *s;
+               const char *s;
 
                s = list[i]->key;
                while (*s)