libopkg: clarify messages and errors related to downloads
[oweals/opkg-lede.git] / libopkg / hash_table.c
index c98296e2128bcad438cd735c9a90225145803bae..37b53e9748a80ca3b7c6483209db8dc9ea8c117e 100644 (file)
@@ -1,7 +1,7 @@
 /* hash.c - hash tables for opkg
 
    Steven M. Ayer, Jamey Hicks
-   
+
    Copyright (C) 2002 Compaq Computer Corporation
 
    This program is free software; you can redistribute it and/or
@@ -15,7 +15,6 @@
    General Public License for more details.
 */
 
-#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -43,13 +42,12 @@ hash_index(hash_table_t *hash, const char *key)
 /*
  * this is an open table keyed by strings
  */
-int
+void
 hash_table_init(const char *name, hash_table_t *hash, int len)
 {
        if (hash->entries != NULL) {
-               fprintf(stderr, "ERROR: %s called on a non empty hash table\n",
-                               __FUNCTION__);
-               return -1;
+               opkg_msg(ERROR, "Internal error: non empty hash table.\n");
+               return;
        }
 
        memset(hash, 0, sizeof(hash_table_t));
@@ -57,8 +55,6 @@ hash_table_init(const char *name, hash_table_t *hash, int len)
        hash->name = name;
        hash->n_buckets = len;
        hash->entries = xcalloc(hash->n_buckets, sizeof(hash_entry_t));
-
-       return 0;
 }
 
 void
@@ -69,7 +65,7 @@ hash_print_stats(hash_table_t *hash)
                "\tmax_bucket_len=%d, n_used_buckets=%d, ave_bucket_len=%.2f\n"
                "\tn_hits=%d, n_misses=%d\n",
                hash->name,
-               hash->n_buckets*sizeof(hash_entry_t),
+               hash->n_buckets*(int)sizeof(hash_entry_t),
                hash->n_buckets,
                hash->n_elements,
                hash->n_collisions,
@@ -112,12 +108,11 @@ void *hash_table_get(hash_table_t *hash, const char *key)
 {
   int ndx= hash_index(hash, key);
   hash_entry_t *hash_entry = hash->entries + ndx;
-  while (hash_entry) 
+  while (hash_entry)
   {
-    if (hash_entry->key) 
+    if (hash_entry->key)
     {
       if (strcmp(key, hash_entry->key) == 0) {
-         // opkg_message(NULL, OPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
         hash->n_hits++;
         return hash_entry->data;
       }
@@ -139,7 +134,7 @@ int hash_table_insert(hash_table_t *hash, const char *key, void *value)
               hash_entry->data = value;
               return 0;
          } else {
-              /* 
+              /*
                * if this is a collision, we have to go to the end of the ll,
                * then add a new entry
                * before we can hook up the value
@@ -175,9 +170,9 @@ int hash_table_remove(hash_table_t *hash, const char *key)
     int ndx= hash_index(hash, key);
     hash_entry_t *hash_entry = hash->entries + ndx;
     hash_entry_t *next_entry=NULL, *last_entry=NULL;
-    while (hash_entry) 
+    while (hash_entry)
     {
-        if (hash_entry->key) 
+        if (hash_entry->key)
         {
             if (strcmp(key, hash_entry->key) == 0) {
                 free(hash_entry->key);
@@ -203,7 +198,7 @@ int hash_table_remove(hash_table_t *hash, const char *key)
 }
 
 void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
-{ 
+{
     int i;
     if (!hash || !f)
        return;