summaryrefslogtreecommitdiff
path: root/ext/gdbm
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-04-15 08:15:27 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-04-15 08:15:27 +0000
commitc7629cdd28904438e5fbe8ff36be9c7010210485 (patch)
tree2b16e3058e566181b1f2e80cfa41986b438c76b7 /ext/gdbm
parentd952e330032662b0adba77f20a13715a1bc0f16e (diff)
* ext/gdbm/gdbm.c (Init_gdbm): define GDBM::READER, GDBM::WRITER,
GDBM::WRCREAT and GDBM::NEWDB. (fgdbm_initialize): use specified read/write flag. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/gdbm')
-rw-r--r--ext/gdbm/gdbm.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index 8499689..ee56fbf 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -16,6 +16,8 @@
static VALUE rb_cGDBM, rb_eGDBMError, rb_eGDBMFatalError;
+#define RUBY_GDBM_RW_BIT 0x20000000
+
#define MY_BLOCK_SIZE (2048)
#define MY_FATAL_FUNC rb_gdbm_fatal
static void
@@ -100,16 +102,23 @@ fgdbm_initialize(argc, argv, obj)
SafeStringValue(file);
- dbm = 0;
- if (mode >= 0)
- dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
- GDBM_WRCREAT|flags, mode, MY_FATAL_FUNC);
- if (!dbm)
+ if (flags & RUBY_GDBM_RW_BIT) {
+ flags &= ~RUBY_GDBM_RW_BIT;
dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
- GDBM_WRITER|flags, 0, MY_FATAL_FUNC);
- if (!dbm)
- dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
- GDBM_READER|flags, 0, MY_FATAL_FUNC);
+ flags, mode, MY_FATAL_FUNC);
+ }
+ else {
+ dbm = 0;
+ if (mode >= 0)
+ dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
+ GDBM_WRCREAT|flags, mode, MY_FATAL_FUNC);
+ if (!dbm)
+ dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
+ GDBM_WRITER|flags, 0, MY_FATAL_FUNC);
+ if (!dbm)
+ dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
+ GDBM_READER|flags, 0, MY_FATAL_FUNC);
+ }
if (!dbm) {
if (mode == -1) return Qnil;
@@ -992,13 +1001,12 @@ Init_gdbm()
rb_define_method(rb_cGDBM, "to_a", fgdbm_to_a, 0);
rb_define_method(rb_cGDBM, "to_hash", fgdbm_to_hash, 0);
- /* flags for gdbm_opn() */
- /*
- rb_define_const(rb_cGDBM, "READER", INT2FIX(GDBM_READER));
- rb_define_const(rb_cGDBM, "WRITER", INT2FIX(GDBM_WRITER));
- rb_define_const(rb_cGDBM, "WRCREAT", INT2FIX(GDBM_WRCREAT));
- rb_define_const(rb_cGDBM, "NEWDB", INT2FIX(GDBM_NEWDB));
- */
+ /* flags for gdbm_open() */
+ rb_define_const(rb_cGDBM, "READER", INT2FIX(GDBM_READER|RUBY_GDBM_RW_BIT));
+ rb_define_const(rb_cGDBM, "WRITER", INT2FIX(GDBM_WRITER|RUBY_GDBM_RW_BIT));
+ rb_define_const(rb_cGDBM, "WRCREAT", INT2FIX(GDBM_WRCREAT|RUBY_GDBM_RW_BIT));
+ rb_define_const(rb_cGDBM, "NEWDB", INT2FIX(GDBM_NEWDB|RUBY_GDBM_RW_BIT));
+
rb_define_const(rb_cGDBM, "FAST", INT2FIX(GDBM_FAST));
/* this flag is obsolete in gdbm 1.8.
On gdbm 1.8, fast mode is default behavior. */