xref: /titanic_52/usr/src/lib/libbc/inc/include/ndbm.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 /*
3  * Copyright (c) 1983 Regents of the University of California.
4  * All rights reserved.  The Berkeley software License Agreement
5  * specifies the terms and conditions for redistribution.
6  *
7  */
8 
9 /*
10  * Hashed key data base library.
11  */
12 
13 #ifndef _ndbm_h
14 #define _ndbm_h
15 
16 #define PBLKSIZ 1024
17 #define DBLKSIZ 4096
18 
19 typedef struct {
20 	int	dbm_dirf;		/* open directory file */
21 	int	dbm_pagf;		/* open page file */
22 	int	dbm_flags;		/* flags, see below */
23 	long	dbm_maxbno;		/* last ``bit'' in dir file */
24 	long	dbm_bitno;		/* current bit number */
25 	long	dbm_hmask;		/* hash mask */
26 	long	dbm_blkptr;		/* current block for dbm_nextkey */
27 	int	dbm_keyptr;		/* current key for dbm_nextkey */
28 	long	dbm_blkno;		/* current page to read/write */
29 	long	dbm_pagbno;		/* current page in pagbuf */
30 	char	dbm_pagbuf[PBLKSIZ];	/* page file block buffer */
31 	long	dbm_dirbno;		/* current block in dirbuf */
32 	char	dbm_dirbuf[DBLKSIZ];	/* directory file block buffer */
33 } DBM;
34 
35 #define _DBM_RDONLY	0x1	/* data base open read-only */
36 #define _DBM_IOERR	0x2	/* data base I/O error */
37 
38 #define dbm_rdonly(db)	((db)->dbm_flags & _DBM_RDONLY)
39 
40 #define dbm_error(db)	((db)->dbm_flags & _DBM_IOERR)
41 	/* use this one at your own risk! */
42 #define dbm_clearerr(db)	((db)->dbm_flags &= ~_DBM_IOERR)
43 
44 /* for flock(2) and fstat(2) */
45 #define dbm_dirfno(db)	((db)->dbm_dirf)
46 #define dbm_pagfno(db)	((db)->dbm_pagf)
47 
48 typedef struct {
49 	char	*dptr;
50 	int	dsize;
51 } datum;
52 
53 /*
54  * flags to dbm_store()
55  */
56 #define DBM_INSERT	0
57 #define DBM_REPLACE	1
58 
59 DBM	*dbm_open();
60 void	dbm_close();
61 datum	dbm_fetch();
62 datum	dbm_firstkey();
63 datum	dbm_nextkey();
64 datum	dbm_do_nextkey();
65 long	dbm_forder();
66 int	dbm_delete();
67 int	dbm_store();
68 
69 #endif /*!_ndbm_h*/
70