xref: /freebsd-src/contrib/libfido2/openbsd-compat/openbsd-compat.h (revision 2ccfa855b2fc331819953e3de1b1c15ce5b95a7e)
10afa8e06SEd Maste /*
2f540a430SEd Maste  * Copyright (c) 2018-2021 Yubico AB. All rights reserved.
30afa8e06SEd Maste  * Use of this source code is governed by a BSD-style
40afa8e06SEd Maste  * license that can be found in the LICENSE file.
5*2ccfa855SEd Maste  * SPDX-License-Identifier: BSD-2-Clause
60afa8e06SEd Maste  */
70afa8e06SEd Maste 
80afa8e06SEd Maste #ifndef _OPENBSD_COMPAT_H
90afa8e06SEd Maste #define _OPENBSD_COMPAT_H
100afa8e06SEd Maste 
110afa8e06SEd Maste #if defined(_MSC_VER)
120afa8e06SEd Maste #include "types.h"
130afa8e06SEd Maste #endif
140afa8e06SEd Maste 
150afa8e06SEd Maste #if defined(HAVE_ENDIAN_H)
160afa8e06SEd Maste #include <endian.h>
170afa8e06SEd Maste #endif
180afa8e06SEd Maste 
190afa8e06SEd Maste #if defined(__APPLE__) && !defined(HAVE_ENDIAN_H)
200afa8e06SEd Maste #include <libkern/OSByteOrder.h>
210afa8e06SEd Maste #define be16toh(x) OSSwapBigToHostInt16((x))
220afa8e06SEd Maste #define htobe16(x) OSSwapHostToBigInt16((x))
230afa8e06SEd Maste #define be32toh(x) OSSwapBigToHostInt32((x))
24f540a430SEd Maste #define htobe32(x) OSSwapHostToBigInt32((x))
250afa8e06SEd Maste #define htole32(x) OSSwapHostToLittleInt32((x))
260afa8e06SEd Maste #define htole64(x) OSSwapHostToLittleInt64((x))
270afa8e06SEd Maste #endif /* __APPLE__ && !HAVE_ENDIAN_H */
280afa8e06SEd Maste 
290afa8e06SEd Maste #if defined(_WIN32) && !defined(HAVE_ENDIAN_H)
300afa8e06SEd Maste #include <stdint.h>
310afa8e06SEd Maste #include <winsock2.h>
320afa8e06SEd Maste #if !defined(_MSC_VER)
330afa8e06SEd Maste #include <sys/param.h>
340afa8e06SEd Maste #endif
350afa8e06SEd Maste #define be16toh(x) ntohs((x))
360afa8e06SEd Maste #define htobe16(x) htons((x))
370afa8e06SEd Maste #define be32toh(x) ntohl((x))
38f540a430SEd Maste #define htobe32(x) htonl((x))
390afa8e06SEd Maste uint32_t htole32(uint32_t);
400afa8e06SEd Maste uint64_t htole64(uint64_t);
410afa8e06SEd Maste #endif /* _WIN32 && !HAVE_ENDIAN_H */
420afa8e06SEd Maste 
43f540a430SEd Maste #if (defined(__FreeBSD__) || defined(__MidnightBSD__)) && !defined(HAVE_ENDIAN_H)
440afa8e06SEd Maste #include <sys/endian.h>
450afa8e06SEd Maste #endif
460afa8e06SEd Maste 
470afa8e06SEd Maste #include <stdlib.h>
480afa8e06SEd Maste #include <string.h>
490afa8e06SEd Maste 
500afa8e06SEd Maste #if !defined(HAVE_STRLCAT)
510afa8e06SEd Maste size_t strlcat(char *, const char *, size_t);
520afa8e06SEd Maste #endif
530afa8e06SEd Maste 
540afa8e06SEd Maste #if !defined(HAVE_STRLCPY)
550afa8e06SEd Maste size_t strlcpy(char *, const char *, size_t);
560afa8e06SEd Maste #endif
570afa8e06SEd Maste 
58f540a430SEd Maste #if !defined(HAVE_STRSEP)
59f540a430SEd Maste char *strsep(char **, const char *);
60f540a430SEd Maste #endif
61f540a430SEd Maste 
620afa8e06SEd Maste #if !defined(HAVE_RECALLOCARRAY)
630afa8e06SEd Maste void *recallocarray(void *, size_t, size_t, size_t);
640afa8e06SEd Maste #endif
650afa8e06SEd Maste 
660afa8e06SEd Maste #if !defined(HAVE_EXPLICIT_BZERO)
670afa8e06SEd Maste void explicit_bzero(void *, size_t);
680afa8e06SEd Maste #endif
690afa8e06SEd Maste 
700afa8e06SEd Maste #if !defined(HAVE_FREEZERO)
710afa8e06SEd Maste void freezero(void *, size_t);
720afa8e06SEd Maste #endif
730afa8e06SEd Maste 
740afa8e06SEd Maste #if !defined(HAVE_GETPAGESIZE)
750afa8e06SEd Maste int getpagesize(void);
760afa8e06SEd Maste #endif
770afa8e06SEd Maste 
780afa8e06SEd Maste #if !defined(HAVE_TIMINGSAFE_BCMP)
790afa8e06SEd Maste int timingsafe_bcmp(const void *, const void *, size_t);
800afa8e06SEd Maste #endif
810afa8e06SEd Maste 
820afa8e06SEd Maste #if !defined(HAVE_READPASSPHRASE)
830afa8e06SEd Maste #include "readpassphrase.h"
840afa8e06SEd Maste #else
850afa8e06SEd Maste #include <readpassphrase.h>
860afa8e06SEd Maste #endif
870afa8e06SEd Maste 
880afa8e06SEd Maste #include <openssl/opensslv.h>
890afa8e06SEd Maste 
900afa8e06SEd Maste #if !defined(HAVE_ERR_H)
910afa8e06SEd Maste #include "err.h"
920afa8e06SEd Maste #else
930afa8e06SEd Maste #include <err.h>
940afa8e06SEd Maste #endif
950afa8e06SEd Maste 
960afa8e06SEd Maste #if !defined(HAVE_GETOPT)
970afa8e06SEd Maste #include "getopt.h"
980afa8e06SEd Maste #else
990afa8e06SEd Maste #include <unistd.h>
1000afa8e06SEd Maste #endif
1010afa8e06SEd Maste 
1020afa8e06SEd Maste #if !defined(HAVE_GETLINE)
1030afa8e06SEd Maste #include <stdio.h>
1040afa8e06SEd Maste ssize_t getline(char **, size_t *, FILE *);
1050afa8e06SEd Maste #endif
1060afa8e06SEd Maste 
1070afa8e06SEd Maste #if defined(_MSC_VER)
1080afa8e06SEd Maste #define strerror_r(e, b, l) strerror_s((b), (l), (e))
1090afa8e06SEd Maste #endif
1100afa8e06SEd Maste 
1110afa8e06SEd Maste #include "time.h"
1120afa8e06SEd Maste 
1130afa8e06SEd Maste #if !defined(HAVE_POSIX_IOCTL)
1140afa8e06SEd Maste #define IOCTL_REQ(x)	(x)
1150afa8e06SEd Maste #else
1160afa8e06SEd Maste #define IOCTL_REQ(x)	((int)(x))
1170afa8e06SEd Maste #endif
1180afa8e06SEd Maste 
119*2ccfa855SEd Maste #if !defined(HAVE_ASPRINTF)
120*2ccfa855SEd Maste int asprintf(char **, const char *, ...);
121*2ccfa855SEd Maste #endif
122*2ccfa855SEd Maste 
1230afa8e06SEd Maste #endif /* !_OPENBSD_COMPAT_H */
124