* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / ext / sdbm / sdbm.h
blobce8f54c4d4edc3bb0a6d8d32cfee60b8240166b2
1 /*
2 * sdbm - ndbm work-alike hashed database library
3 * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
4 * author: oz@nexus.yorku.ca
5 * status: public domain.
6 */
7 #ifndef _SDBM_H_
8 #define _SDBM_H_
10 #define DBLKSIZ 4096
11 #define PBLKSIZ 1024
12 #define PAIRMAX 1008 /* arbitrary on PBLKSIZ-N */
13 #define SPLTMAX 10 /* maximum allowed splits */
14 /* for a single insertion */
15 #define DIRFEXT ".dir"
16 #define PAGFEXT ".pag"
18 typedef struct {
19 int dirf; /* directory file descriptor */
20 int pagf; /* page file descriptor */
21 int flags; /* status/error flags, see below */
22 long maxbno; /* size of dirfile in bits */
23 long curbit; /* current bit number */
24 long hmask; /* current hash mask */
25 long blkptr; /* current block for nextkey */
26 int keyptr; /* current key for nextkey */
27 long blkno; /* current page to read/write */
28 long pagbno; /* current page in pagbuf */
29 char pagbuf[PBLKSIZ]; /* page file block buffer */
30 long dirbno; /* current block in dirbuf */
31 char dirbuf[DBLKSIZ]; /* directory file block buffer */
32 } DBM;
34 #define DBM_RDONLY 0x1 /* data base open read-only */
35 #define DBM_IOERR 0x2 /* data base I/O error */
38 * utility macros
40 #define sdbm_rdonly(db) ((db)->flags & DBM_RDONLY)
41 #define sdbm_error(db) ((db)->flags & DBM_IOERR)
43 #define sdbm_clearerr(db) ((db)->flags &= ~DBM_IOERR) /* ouch */
45 #define sdbm_dirfno(db) ((db)->dirf)
46 #define sdbm_pagfno(db) ((db)->pagf)
48 typedef struct {
49 char *dptr;
50 int dsize;
51 } datum;
53 extern datum nullitem;
55 #if defined(__STDC__) || defined(MSDOS)
56 #define proto(p) p
57 #else
58 #define proto(p) ()
59 #endif
62 * flags to sdbm_store
64 #define DBM_INSERT 0
65 #define DBM_REPLACE 1
68 * ndbm interface
70 extern DBM *sdbm_open proto((char *, int, int));
71 extern void sdbm_close proto((DBM *));
72 extern datum sdbm_fetch proto((DBM *, datum));
73 extern int sdbm_delete proto((DBM *, datum));
74 extern int sdbm_store proto((DBM *, datum, datum, int));
75 extern datum sdbm_firstkey proto((DBM *));
76 extern datum sdbm_nextkey proto((DBM *));
79 * other
81 extern DBM *sdbm_prep proto((char *, char *, int, int));
82 extern long sdbm_hash proto((char *, int));
84 #endif /* _SDBM_H_ */