From: Lloyd Zusman Date: 2004-10-12T03:16:09+09:00 Subject: Re: Forcing DBM.open to be read-only? Mauricio Fern�ndez writes: > On Tue, Oct 12, 2004 at 02:26:10AM +0900, Lloyd Zusman wrote: >> I'd like to use the DBM routines in ruby, and I want to force DBM.open >> to be performed in read-only mode. However, looking at the source code >> (in ext/dbm/dbm.c), it looks like ruby always tries to open the database >> in read-write mode before trying it in read-only mode [see the >> fdbm_initialize() routine, below]. >> >> Am I misinterpreting something? >> >> In any case, how can I do a DBM.open with the guarantee that it will >> never even try to open the file in read-write mode? > > maybe DBM.open(filename, 0666, DBM::READER) ? > (that sets the RUBY_DBM_RW_BIT... ) That logic is a little confusing to me: by _setting_ RUBY_DBM_RW_BIT in the flags that are passed to DBM.open, that causes the bit to get _cleared_ before the dbm_open call gets made. That seems counter-intuitive, but as long as it works, I'm not going to complain. :) Thanks. >> if (rb_scan_args(argc, argv, "12", &file, &vmode, &vflags) == 1) { >> mode = 0666; /* default value */ >> } > [...] >> if (flags & RUBY_DBM_RW_BIT) { >> flags &= ~RUBY_DBM_RW_BIT; >> dbm = dbm_open(RSTRING(file)->ptr, flags, mode); >> } -- Lloyd Zusman ljz@asfast.com God bless you.