From ae730cd65f8fb4573fe499e1bd4ecdc5054f5c4e Mon Sep 17 00:00:00 2001
From: alex <alex@c028cbd2-c16b-5b4b-a496-9718f37d4682>
Date: Tue, 4 Jul 1995 19:29:55 +0000
Subject: [PATCH] Correzioni ulteriori a DB_rewrite e DB_seek

git-svn-id: svn://10.65.10.50/trunk@1554 c028cbd2-c16b-5b4b-a496-9718f37d4682
---
 include/codeb.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/codeb.c b/include/codeb.c
index beb01b7ee..8d8c40960 100755
--- a/include/codeb.c
+++ b/include/codeb.c
@@ -315,15 +315,21 @@ int DB_unlock(int handle)
   --------------------------------------------------------------------------*/
 int DB_seek(int handle,char *key)
 {                                      
-  int rc;  
-  TAG4 * tt;
+  int rc, len;  
+  TAG4 * tt;  
+  char * k;
 
   if(dbdata[handle]==0) return(-1);
   rc = x4seek(&xdb[handle],key);
   if (rc)
     return rc;                           
-  tt = d4tag_selected(dbdata[handle]);
-  rc = strncmp(key, t4key(tt), expr4key_len(tt->expr));
+  tt = d4tag_selected(dbdata[handle]); 
+  len = expr4key_len(tt->expr);
+  k = strdup(t4key(tt));
+  while (--len >= 0 && k[len] == ' ')
+    k[len] = '\0';  
+  rc = strcmp(key, k);
+  free(k);
   if (rc == 0)
     return 0;
   else 
@@ -417,8 +423,8 @@ int DB_rewrite(int handle)
   int rt;
   if(dbdata[handle]==0) return(-1);
   rt=d4write(dbdata[handle],d4recno(dbdata[handle]));
-  if (rt!=r4success)
-    rt=DB_unlock(handle);
+  if (rt==r4success)
+    DB_unlock(handle);
   return (rt);
 }