From 5f11916d28a6ec0406a5f4ecaaf52665568ccf29 Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 22 Feb 2014 00:20:00 +0100 Subject: [PATCH] Bump sdb fixing disk storage issue --- shlr/sdb/src/disk.c | 2 +- shlr/sdb/src/sdb.c | 24 +++++------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/shlr/sdb/src/disk.c b/shlr/sdb/src/disk.c index 3e832fd3d0..052dbc426e 100644 --- a/shlr/sdb/src/disk.c +++ b/shlr/sdb/src/disk.c @@ -50,7 +50,7 @@ SDB_API int sdb_disk_create (Sdb* s) { strcpy (str+nlen, ".tmp"); s->fdump = open (str, O_BINARY|O_RDWR|O_CREAT|O_TRUNC, 0644); if (s->fdump == -1) { - fprintf (stderr, "sdb: Cannot open '%s' for writing.\n", str); + eprintf ("sdb: Cannot open '%s' for writing.\n", str); free (str); return 0; } diff --git a/shlr/sdb/src/sdb.c b/shlr/sdb/src/sdb.c index c02c10c7d7..07f2e23766 100644 --- a/shlr/sdb/src/sdb.c +++ b/shlr/sdb/src/sdb.c @@ -124,7 +124,7 @@ SDB_API const char *sdb_const_get (Sdb* s, const char *key, ut32 *cas) { if (cas) *cas = 0; if (!s||!key) return NULL; keylen = strlen (key)+1; - hash = sdb_hash (key, keylen); + hash = sdb_hash (key, keylen-1); /* search in memory */ kv = (SdbKv*)ht_lookup (s->ht, hash); @@ -164,7 +164,7 @@ SDB_API char *sdb_get (Sdb* s, const char *key, ut32 *cas) { if (cas) *cas = 0; if (!s || !key) return NULL; keylen = strlen (key)+1; - hash = sdb_hash (key, keylen); + hash = sdb_hash (key, keylen-1); /* search in memory */ kv = (SdbKv*)ht_lookup (s->ht, hash); @@ -280,7 +280,7 @@ SDB_API int sdb_set (Sdb* s, const char *key, const char *val, ut32 cas) { if (!sdb_check_value (val)) return 0; klen = strlen (key)+1; - hash = sdb_hash (key, klen); + hash = sdb_hash (key, klen-1); cdb_findstart (&s->db); e = ht_search (s->ht, hash); if (e) { @@ -312,16 +312,7 @@ SDB_API void sdb_foreach (Sdb* s, SdbForeachCallback cb, void *user) { ls_foreach (s->ht->list, iter, kv) { if (!kv->value || !*kv->value) continue; - if (strchr (kv->value, SDB_RS)) { - char *o, *p = strdup (kv->value); - for (o=p; *o; o++) if (*o==SDB_RS) *o = ','; - o = malloc (strlen (kv->key)+3); - memcpy (o, "()", 2); - strcpy (o+2, kv->key); - cb (user, o, p); - free (o); - free (p); - } else cb (user, kv->key, kv->value); + cb (user, kv->key, kv->value); } } @@ -334,12 +325,7 @@ SDB_API void sdb_list (Sdb* s) { ls_foreach (s->ht->list, iter, kv) { if (!kv->value || !*kv->value) continue; - if (strchr (kv->value, SDB_RS)) { - char *o, *p = strdup (kv->value); - for (o=p; *o; o++) if (*o==SDB_RS) *o = ','; - printf ("()%s=%s\n", kv->key, p); - free (p); - } else printf ("%s=%s\n", kv->key, kv->value); + printf ("%s=\"%s\"\n", kv->key, kv->value); } }