xref: /titanic_51/usr/src/head/ndbm.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 /*
36  * Hashed key data base library.
37  */
38 
39 #ifndef _NDBM_H
40 #define	_NDBM_H
41 
42 #pragma ident	"%Z%%M%	%I%	%E% SMI"
43 
44 #include <sys/feature_tests.h>
45 #include <sys/types.h>
46 
47 #ifdef	__cplusplus
48 extern "C" {
49 #endif
50 
51 /*
52  * flags to dbm_store()
53  */
54 #define	DBM_INSERT	0
55 #define	DBM_REPLACE	1
56 
57 #define	_PBLKSIZ 1024
58 #define	_DBLKSIZ 4096
59 
60 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
61 #define	PBLKSIZ _PBLKSIZ
62 #define	DBLKSIZ _DBLKSIZ
63 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
64 
65 typedef struct {
66 	int	dbm_dirf;		/* open directory file */
67 	int	dbm_pagf;		/* open page file */
68 	int	dbm_flags;		/* flags, see below */
69 	long	dbm_maxbno;		/* last ``bit'' in dir file */
70 	long	dbm_bitno;		/* current bit number */
71 	long	dbm_hmask;		/* hash mask */
72 	long	dbm_blkptr;		/* current block for dbm_nextkey */
73 	int	dbm_keyptr;		/* current key for dbm_nextkey */
74 	long	dbm_blkno;		/* current page to read/write */
75 	long	dbm_pagbno;		/* current page in pagbuf */
76 	char	dbm_pagbuf[_PBLKSIZ];	/* page file block buffer */
77 	long	dbm_dirbno;		/* current block in dirbuf */
78 	char	dbm_dirbuf[_DBLKSIZ];	/* directory file block buffer */
79 } DBM;
80 
81 #if defined(_XPG4_2)
82 typedef struct {
83 	void	*dptr;
84 	size_t	dsize;
85 } datum;
86 #else
87 typedef struct {
88 	char	*dptr;
89 	long	dsize;
90 } datum;
91 #endif
92 
93 #ifdef	__STDC__
94 DBM	*dbm_open(const char *, int, mode_t);
95 void	dbm_close(DBM *);
96 datum	dbm_fetch(DBM *, datum);
97 datum	dbm_firstkey(DBM *);
98 datum	dbm_nextkey(DBM *);
99 int	dbm_delete(DBM *, datum);
100 int	dbm_store(DBM *, datum, datum, int);
101 int	dbm_clearerr(DBM *);
102 int	dbm_error(DBM *);
103 #else
104 DBM	*dbm_open();
105 void	dbm_close();
106 datum	dbm_fetch();
107 datum	dbm_firstkey();
108 datum	dbm_nextkey();
109 int	dbm_delete();
110 int	dbm_store();
111 int	dbm_clearerr();
112 int	dbm_error();
113 #endif
114 
115 #define	_DBM_RDONLY	0x1	/* data base open read-only */
116 #define	_DBM_IOERR	0x2	/* data base I/O error */
117 
118 #define	dbm_rdonly(__db)	((__db)->dbm_flags & _DBM_RDONLY)
119 #define	dbm_error(__db)		((__db)->dbm_flags & _DBM_IOERR)
120 /* use this one at your own risk! */
121 #define	dbm_clearerr(__db)	((__db)->dbm_flags &= ~_DBM_IOERR)
122 /* for fstat(2) */
123 #define	dbm_dirfno(__db)	((__db)->dbm_dirf)
124 #define	dbm_pagfno(__db)	((__db)->dbm_pagf)
125 
126 #ifdef	__cplusplus
127 }
128 #endif
129 
130 #endif	/* _NDBM_H */
131