xref: /netbsd-src/external/mpl/bind/dist/lib/isc/include/isc/magic.h (revision e6c7e151de239c49d2e38720a061ed9d1fa99309)
1 /*	$NetBSD: magic.h,v 1.2 2018/08/12 13:02:38 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 
15 #ifndef ISC_MAGIC_H
16 #define ISC_MAGIC_H 1
17 
18 #include <isc/likely.h>
19 
20 /*! \file isc/magic.h */
21 
22 typedef struct {
23 	unsigned int magic;
24 } isc__magic_t;
25 
26 
27 /*%
28  * To use this macro the magic number MUST be the first thing in the
29  * structure, and MUST be of type "unsigned int".
30  * The intent of this is to allow magic numbers to be checked even though
31  * the object is otherwise opaque.
32  */
33 #define ISC_MAGIC_VALID(a,b)	(ISC_LIKELY((a) != NULL) && \
34 				 ISC_LIKELY(((const isc__magic_t *)(a))->magic == (b)))
35 
36 #define ISC_MAGIC(a, b, c, d)	((a) << 24 | (b) << 16 | (c) << 8 | (d))
37 
38 #endif /* ISC_MAGIC_H */
39