This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Why is dbm_store saving garbage to file?


Okay, here's my guess:

  You're using gdbm, but you're using it in its 'ndbm-emulation' mode. 
True NDBM database usually have two files, foo.pag and foo.dir.  GDBM
databases have only a single file.  GDBM emulates NDBM operation by
creating its database file as foo.pag, and hardlinks foo.dir to it. 

Hard links don't work on FAT drives, or on Win9x.  Symlinks can't be
used, because you need the timestamps on both "files" to be the same;
symlinks do not inherit their target's timestamp.

Therefore, gdbm's ndbm-emulation mode doesn't work in those
circumstances.  Are you on Win9x or using FAT drives?

--Chuck

P.S. Be warned that the documentation in the source code,
gdbm-1.8.0/dbm_open.c is a little misleading. "NOTE: file.dir will be
ignored and will always have a size of zero." This statement is untrue
-- on database creation, file.dir is created as a hardlink to file.pag. 
If the database has already been created, then yes, "file.dir" is
ignored.  But it never has a size of zero.

Jeff Lu wrote:
> 
> It's calling from gdbm.  Here's the flag I used to compile -lgdbm.
> 
> After doing some more debugging, I realized the returned file handle is
> always NULL.  So for some reason it's not able to open the file but it did
> create it.
> 
> Thanks
> 
> -----Original Message-----
> From: cwilson@ece.gatech.edu [mailto:cwilson@ece.gatech.edu]
> Sent: Tuesday, December 12, 2000 1:31 AM
> To: Jeff Lu
> Cc: cygwin@cygwin.com
> Subject: Re: Why is dbm_store saving garbage to file?
> 
> Jeff Lu wrote:
> >
> > Hi,
> >
> > I'm trying to save some data using dbm but what's being written to the
> file
> > is just gibberish.  The same code works in Unix/Linux.  Here's the code:
> >
> >         dbm_local = dbm_open (database, O_RDWR|O_CREAT, 00664);
> >         if(dbm_local)
> >         {
> >           strcpy(buffer, "CurrentOrderNumber");
> >           key.dptr = buffer;
> >           key.dsize = strlen(buffer)+1;
> >           return_data = dbm_fetch(dbm_local, key);
> >           if(return_data.dptr)
> >             sprintf(count, "%d", atoi(return_data.dptr)+1);
> >           else
> >             strcpy(count, "1");
> >           data_data.dptr = count;
> >           data_data.dsize = strlen(count)+1;
> >           dbm_store(dbm_local, key, data_data, DBM_REPLACE);
> >           dbm_close (dbm_local);
> >         }
> >
> > Thanks
> 
> In which library are dbm_open, dbm_fetch, dbm_store, and dbm_close
> implemented?  Are you using ndbm?  dbm?  Berkeley db?  or gdbm?  (Note
> that only gdbm is a supported, 'official' cygwin package.)
> 
> --Chuck

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]