xref: /netbsd-src/external/bsd/libfido2/dist/src/packed.h (revision 2d40c4512a84c0d064ec30a492c5e2a14d230bc3)
1ba9bdd8bSchristos /*
2ba9bdd8bSchristos  * Copyright (c) 2018 Yubico AB. All rights reserved.
3ba9bdd8bSchristos  * Use of this source code is governed by a BSD-style
4ba9bdd8bSchristos  * license that can be found in the LICENSE file.
5*2d40c451Schristos  * SPDX-License-Identifier: BSD-2-Clause
6ba9bdd8bSchristos  */
7ba9bdd8bSchristos 
8ba9bdd8bSchristos #ifndef _PACKED_H
9ba9bdd8bSchristos #define _PACKED_H
10ba9bdd8bSchristos 
11ba9bdd8bSchristos #if defined(__GNUC__)
12ba9bdd8bSchristos #define PACKED_TYPE(type, def)	\
13ba9bdd8bSchristos 	typedef def __attribute__ ((__packed__)) type;
14ba9bdd8bSchristos #elif defined(_MSC_VER)
15ba9bdd8bSchristos #define PACKED_TYPE(type, def)	\
16ba9bdd8bSchristos 	__pragma(pack(push, 1))	\
17ba9bdd8bSchristos 	typedef def type;	\
18ba9bdd8bSchristos 	__pragma(pack(pop))
19ba9bdd8bSchristos #else
20ba9bdd8bSchristos #error "please provide a way to define packed types on your platform"
21ba9bdd8bSchristos #endif
22ba9bdd8bSchristos 
23ba9bdd8bSchristos #endif /* !_PACKED_H */
24