2 * Copyright (c) 2018 Yubico AB. All rights reserved.
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file.
7 #ifndef _OPENBSD_COMPAT_H
8 #define _OPENBSD_COMPAT_H
14 #if defined(HAVE_ENDIAN_H)
18 #if defined(__APPLE__) && !defined(HAVE_ENDIAN_H)
19 #include <libkern/OSByteOrder.h>
20 #define be16toh(x) OSSwapBigToHostInt16((x))
21 #define htobe16(x) OSSwapHostToBigInt16((x))
22 #define be32toh(x) OSSwapBigToHostInt32((x))
23 #define htole32(x) OSSwapHostToLittleInt32((x))
24 #define htole64(x) OSSwapHostToLittleInt64((x))
25 #endif /* __APPLE__ && !HAVE_ENDIAN_H */
27 #if defined(_WIN32) && !defined(HAVE_ENDIAN_H)
30 #if !defined(_MSC_VER)
31 #include <sys/param.h>
33 #define be16toh(x) ntohs((x))
34 #define htobe16(x) htons((x))
35 #define be32toh(x) ntohl((x))
36 uint32_t htole32(uint32_t);
37 uint64_t htole64(uint64_t);
38 #endif /* _WIN32 && !HAVE_ENDIAN_H */
40 #if defined(__FreeBSD__) && !defined(HAVE_ENDIAN_H)
41 #include <sys/endian.h>
47 #if !defined(HAVE_STRLCAT)
48 size_t strlcat(char *, const char *, size_t);
51 #if !defined(HAVE_STRLCPY)
52 size_t strlcpy(char *, const char *, size_t);
55 #if !defined(HAVE_RECALLOCARRAY)
56 void *recallocarray(void *, size_t, size_t, size_t);
59 #if !defined(HAVE_EXPLICIT_BZERO)
60 void explicit_bzero(void *, size_t);
63 #if !defined(HAVE_FREEZERO)
64 void freezero(void *, size_t);
67 #if !defined(HAVE_GETPAGESIZE)
68 int getpagesize(void);
71 #if !defined(HAVE_TIMINGSAFE_BCMP)
72 int timingsafe_bcmp(const void *, const void *, size_t);
75 #if !defined(HAVE_READPASSPHRASE)
76 #include "readpassphrase.h"
78 #include <readpassphrase.h>
81 #include <openssl/opensslv.h>
83 #if OPENSSL_VERSION_NUMBER < 0x10100000L
86 #define EVP_PKEY_get0_EC_KEY(x) ((x)->pkey.ec)
87 #define EVP_PKEY_get0_RSA(x) ((x)->pkey.rsa)
90 #if !defined(HAVE_ERR_H)
96 #if !defined(HAVE_GETOPT)
102 #if !defined(HAVE_GETLINE)
104 ssize_t getline(char **, size_t *, FILE *);
107 #if defined(_MSC_VER)
108 #define strerror_r(e, b, l) strerror_s((b), (l), (e))
113 #if !defined(HAVE_POSIX_IOCTL)
114 #define IOCTL_REQ(x) (x)
116 #define IOCTL_REQ(x) ((int)(x))
119 #endif /* !_OPENBSD_COMPAT_H */