From: "Juan Manuel Guerrero" Organization: Darmstadt University of Technology To: Igor Bujna Date: Tue, 21 Aug 2001 10:26:23 +0200 Subject: Re: Problem with GDBM-1.8.0 CC: djgpp AT delorie DOT com In-reply-to: <3B7FE715.10486.1C33B73@localhost> X-mailer: Pegasus Mail for Windows (v2.54DE) Message-ID: <4D7FD3B1B7A@HRZ1.hrz.tu-darmstadt.de> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sun, 19 Aug 2001, Igor Bujna wrote: > Hi, > i have problem with function gdbm_open in gdbm-1.8.0. > When i use GDBM_WRCREAT or GDBM_NEWDB flag and then i > want put some data to file i get message "gdbm fatal: read error:". > This is my test.c file: [snip] > I think problem somewhere when gdbm creating file,because > when i compile and run this file (test.c) on my linux is everything OK. > File "test.dbf" look on linux OK.But when I run under DJGPP file > "test.dbf" look damage.This problem is same when i try run > testgdbm program, which is in yours gdbm-1.8.0-source(i try on > yours binary or source). It is not possible to me to reproduce the error message you described. Netherless the port is broken. I have tried your test program on DOS 6.22 and Win95 with the actual port (timestamp:2001-05-25) and it always aborts with the following traceback: D:\test>a Exiting due to signal SIGSEGV Page fault at eip=000033b8, error=0004 eax=00000000 ebx=02000000 ecx=0000102e edx=00000000 esi=06000000 edi=00097e84 ebp=000976b0 esp=000976a4 program=D:\TEST\A.EXE cs: sel=00af base=82960000 limit=ffed0fff ds: sel=00b7 base=82960000 limit=ffed0fff es: sel=00b7 base=82960000 limit=ffed0fff fs: sel=0087 base=000081a0 limit=0000ffff gs: sel=00c7 base=00000000 limit=0010ffff ss: sel=00b7 base=82960000 limit=ffed0fff App stack: [000977b0..000177b0] Exceptn stack: [00017704..000157c4] Call frame traceback EIPs: 0x000033b8 _get_elem+84, line 316 of falloc.c 0x00002f31 __gdbm_alloc+33, line 70 of falloc.c 0x00001f23 _gdbm_store+235, line 124 of gdbmstore.c 0x0000168c _main+228, line 15 of a.c 0x00004cc2 ___crt1_startup+178 The reason for this failure is that all files are *opened* and/or *created* in dos text mode instead of binary mode. This has the concequence that pointers and indices are initialized with wrong data making the hole library fail. I have fixed this and I will upload a corrected port ASAP. The patch below based on the actual DJGPP port will fix the dificulty and it contains a small test program to read a GDBM file created with your test program. Please note that you must recompile the sources to get a working library. Thank you for the bug report and excuse the inconveniences caused. Regards, Guerrero, Juan Manuel diff -acprNC3 gdbm-1.8-0.orig/_test.c gdbm-1.8-0/_test.c *** gdbm-1.8-0.orig/_test.c Thu Jan 1 00:00:00 1970 --- gdbm-1.8-0/_test.c Tue Aug 21 04:20:54 2001 *************** *** 0 **** --- 1,39 ---- + #include + #include + #include + #include + + main (int argc, char *argv[]) + { + GDBM_FILE dbf; + datum key, data; + + if (argc < 3) + { + fprintf (stderr, "Usage: %s \n\n", argv[0]); + exit (1); + } + + dbf = gdbm_open (argv[1], 512, GDBM_READER, 0664, NULL); + if (!dbf) + { + fprintf (stderr, "File %s either doesn't exist or is not a gdbm file.\n", argv[1]); + exit (2); + } + + + key.dptr = argv[2]; + key.dsize = strlen (argv[2]) + 1; + + data = gdbm_fetch (dbf, key); + + if (data.dsize > 0) + { + printf ("Key: %s Data: %s\n", key.dptr, data.dptr); + free (data.dptr); + } + else + printf ("Key %s not found.\n", argv[2]); + + gdbm_close (dbf); + } diff -acprNC3 gdbm-1.8-0.orig/gdbmopen.c gdbm-1.8-0/gdbmopen.c *** gdbm-1.8-0.orig/gdbmopen.c Wed May 19 00:16:06 1999 --- gdbm-1.8-0/gdbmopen.c Tue Aug 21 04:08:46 2001 *************** gdbm_open (file, block_size, flags, mode *** 126,146 **** switch (flags & GDBM_OPENMASK) { case GDBM_READER: ! dbf->desc = open (dbf->name, O_RDONLY, 0); break; case GDBM_OPENMASK: ! dbf->desc = open (dbf->name, O_RDWR, 0); break; case GDBM_NEWDB: ! dbf->desc = open (dbf->name, O_RDWR|O_CREAT, mode); flags = GDBM_WRITER; need_trunc = TRUE; break; default: ! dbf->desc = open (dbf->name, O_RDWR|O_CREAT, mode); flags = GDBM_WRITER; break; --- 126,146 ---- switch (flags & GDBM_OPENMASK) { case GDBM_READER: ! dbf->desc = open (dbf->name, O_RDONLY|O_BINARY, 0); break; case GDBM_OPENMASK: ! dbf->desc = open (dbf->name, O_RDWR|O_BINARY, 0); break; case GDBM_NEWDB: ! dbf->desc = open (dbf->name, O_RDWR|O_CREAT|O_BINARY, mode); flags = GDBM_WRITER; need_trunc = TRUE; break; default: ! dbf->desc = open (dbf->name, O_RDWR|O_CREAT|O_BINARY, mode); flags = GDBM_WRITER; break;