xref: /netbsd-src/external/mpl/bind/dist/lib/isc/include/isc/magic.h (revision 4d342c046e3288fb5a1edcd33cfec48c41c80664)
1 /*	$NetBSD: magic.h,v 1.3 2020/05/24 19:46:26 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  * See the COPYRIGHT file distributed with this work for additional
11  * information regarding copyright ownership.
12  */
13 
14 #ifndef ISC_MAGIC_H
15 #define ISC_MAGIC_H 1
16 
17 #include <isc/likely.h>
18 
19 /*! \file isc/magic.h */
20 
21 typedef struct {
22 	unsigned int magic;
23 } isc__magic_t;
24 
25 /*%
26  * To use this macro the magic number MUST be the first thing in the
27  * structure, and MUST be of type "unsigned int".
28  * The intent of this is to allow magic numbers to be checked even though
29  * the object is otherwise opaque.
30  */
31 #define ISC_MAGIC_VALID(a, b)       \
32 	(ISC_LIKELY((a) != NULL) && \
33 	 ISC_LIKELY(((const isc__magic_t *)(a))->magic == (b)))
34 
35 #define ISC_MAGIC(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
36 
37 #endif /* ISC_MAGIC_H */
38