xref: /openbsd/lib/libc/hidden/db.h (revision b5745d08)
1 /*	$OpenBSD: db.h,v 1.4 2016/05/29 20:47:49 guenther Exp $	*/
2 /*
3  * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef _LIBC_DB_H_
19 #define	_LIBC_DB_H_
20 
21 #include_next <db.h>
22 
23 /*
24  * Little endian <==> big endian 32-bit swap macros.
25  *	M_32_SWAP	swap a memory location
26  *	P_32_SWAP	swap a referenced memory location
27  *	P_32_COPY	swap from one location to another
28  */
29 #define	M_32_SWAP(a) {							\
30 	u_int32_t _tmp = a;						\
31 	((char *)&a)[0] = ((char *)&_tmp)[3];				\
32 	((char *)&a)[1] = ((char *)&_tmp)[2];				\
33 	((char *)&a)[2] = ((char *)&_tmp)[1];				\
34 	((char *)&a)[3] = ((char *)&_tmp)[0];				\
35 }
36 #define	P_32_SWAP(a) {							\
37 	u_int32_t _tmp = *(u_int32_t *)a;				\
38 	((char *)a)[0] = ((char *)&_tmp)[3];				\
39 	((char *)a)[1] = ((char *)&_tmp)[2];				\
40 	((char *)a)[2] = ((char *)&_tmp)[1];				\
41 	((char *)a)[3] = ((char *)&_tmp)[0];				\
42 }
43 #define	P_32_COPY(a, b) {						\
44 	((char *)&(b))[0] = ((char *)&(a))[3];				\
45 	((char *)&(b))[1] = ((char *)&(a))[2];				\
46 	((char *)&(b))[2] = ((char *)&(a))[1];				\
47 	((char *)&(b))[3] = ((char *)&(a))[0];				\
48 }
49 
50 /*
51  * Little endian <==> big endian 16-bit swap macros.
52  *	M_16_SWAP	swap a memory location
53  *	P_16_SWAP	swap a referenced memory location
54  *	P_16_COPY	swap from one location to another
55  */
56 #define	M_16_SWAP(a) {							\
57 	u_int16_t _tmp = a;						\
58 	((char *)&a)[0] = ((char *)&_tmp)[1];				\
59 	((char *)&a)[1] = ((char *)&_tmp)[0];				\
60 }
61 #define	P_16_SWAP(a) {							\
62 	u_int16_t _tmp = *(u_int16_t *)a;				\
63 	((char *)a)[0] = ((char *)&_tmp)[1];				\
64 	((char *)a)[1] = ((char *)&_tmp)[0];				\
65 }
66 #define	P_16_COPY(a, b) {						\
67 	((char *)&(b))[0] = ((char *)&(a))[1];				\
68 	((char *)&(b))[1] = ((char *)&(a))[0];				\
69 }
70 
71 __BEGIN_HIDDEN_DECLS
72 DB	*__bt_open(const char *, int, int, const BTREEINFO *, int);
73 DB	*__hash_open(const char *, int, int, const HASHINFO *, int);
74 DB	*__rec_open(const char *, int, int, const RECNOINFO *, int);
75 void	__dbpanic(DB *dbp);
76 
77 /* Default hash function, from db/hash/hash_func.c */
78 u_int32_t	__default_hash(const void *, size_t);
79 __END_HIDDEN_DECLS
80 
81 PROTO_NORMAL(dbopen);
82 
83 #endif /* !_LIBC_DB_H_ */
84