gdbm: more user-friendly initial configuration

db4
Dmitry Shubin 2010-06-27 01:29:47 +04:00
parent 9a1a60f804
commit 4720a1aad3
2 changed files with 16 additions and 10 deletions

View File

@ -14,10 +14,8 @@ LIBRARY: libgdbm
C-GLOBAL: c-string gdbm_version
CONSTANT: GDBM_READER 0
CONSTANT: GDBM_WRITER 1
CONSTANT: GDBM_WRCREAT 2
CONSTANT: GDBM_NEWDB 3
ENUM: gdbm-role reader writer wrcreat newdb ;
CONSTANT: GDBM_SYNC HEX: 20
CONSTANT: GDBM_NOLOCK HEX: 40

View File

@ -1,14 +1,16 @@
! Copyright (C) 2010 Dmitry Shubin.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data alien.destructors
classes.struct combinators destructors gdbm.ffi io.backend kernel libc
literals locals math namespaces sequences serialize strings ;
alien.enums classes.struct combinators destructors gdbm.ffi io.backend
kernel libc locals math namespaces sequences serialize strings ;
IN: gdbm
TUPLE: gdbm
{ name string }
{ block-size integer }
{ flags integer initial: $ GDBM_WRCREAT }
{ role initial: wrcreat }
{ sync boolean }
{ nolock boolean }
{ mode integer initial: OCT: 644 } ;
@ -22,10 +24,16 @@ SYMBOL: current-dbf
: dbf ( -- dbf ) current-dbf get ;
: get-flag ( gdbm -- n )
[ role>> enum>number ]
[ sync>> GDBM_SYNC 0 ? ]
[ nolock>> GDBM_NOLOCK 0 ? ]
tri bitor bitor ;
: gdbm-open ( gdbm -- dbf )
{
[ name>> normalize-path ]
[ block-size>> ] [ flags>> ] [ mode>> ]
[ block-size>> ] [ get-flag ] [ mode>> ]
} cleave f gdbm_open [ gdbm-throw ] unless* ;
DESTRUCTOR: gdbm-close