about summary refs log tree commit diff
path: root/Src/Modules
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2008-07-21 01:47:59 +0000
committerClint Adams <clint@users.sourceforge.net>2008-07-21 01:47:59 +0000
commitfdf44493380feb99f8cbb5222df648f23bdcb731 (patch)
tree768b57a7ce288f4d1f3c786addfbd7a0906ab2fa /Src/Modules
parent9f42d3211e9c8dce63f59d0cc5fd40a221384026 (diff)
downloadzsh-fdf44493380feb99f8cbb5222df648f23bdcb731.tar.gz
zsh-fdf44493380feb99f8cbb5222df648f23bdcb731.tar.xz
zsh-fdf44493380feb99f8cbb5222df648f23bdcb731.zip
25320: fix read and write of elements by key.
Diffstat (limited to 'Src/Modules')
-rw-r--r--Src/Modules/db_gdbm.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index f0915e0a8..d8f6724ea 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -39,7 +39,7 @@
 
 #include <gdbm.h>
 
-static const struct gsu_hash gdbm_gsu =
+static const struct gsu_scalar gdbm_gsu =
 { gdbmgetfn, gdbmsetfn, gdbmunsetfn };
 
 static struct builtin bintab[] = {
@@ -105,26 +105,47 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func))
     return 0;
 }
 
-
 /**/
 static char *
 gdbmgetfn(Param pm)
 {
-return;
+    datum key, content;
+    int ret;
+
+    key.dptr = pm->node.nam;
+    key.dsize = strlen(key.dptr) + 1;
+
+    ret = gdbm_exists(dbf, key);
+    if(ret) {
+        content = gdbm_fetch(dbf, key);
+    } else {
+        content.dptr = dupstring("");
+    }
+
+    return content.dptr;
 }
 
 /**/
 static void
-gdbmsetfn(Param pm, char **key)
+gdbmsetfn(Param pm, char **val)
 {
-return;
+    datum key, content;
+    int ret;
+
+
+    key.dptr = pm->node.nam;
+    key.dsize = strlen(key.dptr) + 1;
+    content.dptr = val;
+    content.dsize = strlen(content.dptr) + 1;
+
+    ret = gdbm_store(dbf, key, content, GDBM_REPLACE);
 }
 
 /**/
 static void
 gdbmunsetfn(Param pm, int um)
 {
-return;
+
 }
 
 /**/
@@ -143,17 +164,8 @@ getgdbmnode(UNUSED(HashTable ht), const char *name)
     pm = (Param) hcalloc(sizeof(struct param));
     pm->node.nam = nameu;
     pm->node.flags = PM_SCALAR;
+    pm->gsu.s = &gdbm_gsu;
 
-    ret = gdbm_exists(dbf, key);
-    if(!ret) {
-	pm->u.str = dupstring("");
-	pm->node.flags |= PM_UNSET;
-    } else {
-	content = gdbm_fetch(dbf, key);
-
-	pm->u.str = content.dptr;
-	pm->gsu.s = &nullsetscalar_gsu;
-    }
     return &pm->node;
 }