2 * Copyright (c) 2018-2021 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.
5 * SPDX-License-Identifier: BSD-2-Clause
8 #ifndef _OPENBSD_COMPAT_H
9 #define _OPENBSD_COMPAT_H
15 #if defined(HAVE_ENDIAN_H)
19 #if defined(__APPLE__) && !defined(HAVE_ENDIAN_H)
20 #include <libkern/OSByteOrder.h>
21 #define be16toh(x) OSSwapBigToHostInt16((x))
22 #define htobe16(x) OSSwapHostToBigInt16((x))
23 #define be32toh(x) OSSwapBigToHostInt32((x))
24 #define htobe32(x) OSSwapHostToBigInt32((x))
25 #define htole32(x) OSSwapHostToLittleInt32((x))
26 #define htole64(x) OSSwapHostToLittleInt64((x))
27 #endif /* __APPLE__ && !HAVE_ENDIAN_H */
29 #if defined(_WIN32) && !defined(HAVE_ENDIAN_H)
32 #if !defined(_MSC_VER)
33 #include <sys/param.h>
35 #define be16toh(x) ntohs((x))
36 #define htobe16(x) htons((x))
37 #define be32toh(x) ntohl((x))
38 #define htobe32(x) htonl((x))
39 uint32_t htole32(uint32_t);
40 uint64_t htole64(uint64_t);
41 #endif /* _WIN32 && !HAVE_ENDIAN_H */
43 #if (defined(__FreeBSD__) || defined(__MidnightBSD__)) && !defined(HAVE_ENDIAN_H)
44 #include <sys/endian.h>
50 #if !defined(HAVE_STRLCAT)
51 size_t strlcat(char *, const char *, size_t);
54 #if !defined(HAVE_STRLCPY)
55 size_t strlcpy(char *, const char *, size_t);
58 #if !defined(HAVE_STRSEP)
59 char *strsep(char **, const char *);
62 #if !defined(HAVE_RECALLOCARRAY)
63 void *recallocarray(void *, size_t, size_t, size_t);
66 #if !defined(HAVE_EXPLICIT_BZERO)
67 void explicit_bzero(void *, size_t);
70 #if !defined(HAVE_FREEZERO)
71 void freezero(void *, size_t);
74 #if !defined(HAVE_GETPAGESIZE)
75 int getpagesize(void);
78 #if !defined(HAVE_TIMINGSAFE_BCMP)
79 int timingsafe_bcmp(const void *, const void *, size_t);
82 #if !defined(HAVE_READPASSPHRASE)
83 #include "readpassphrase.h"
85 #include <readpassphrase.h>
88 #include <openssl/opensslv.h>
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 #if !defined(HAVE_ASPRINTF)
120 int asprintf(char **, const char *, ...);
123 #endif /* !_OPENBSD_COMPAT_H */