1 /* 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 */ 6 7 #ifndef _OPENBSD_COMPAT_H 8 #define _OPENBSD_COMPAT_H 9 10 #if defined(_MSC_VER) 11 #include "types.h" 12 #endif 13 14 #if defined(HAVE_ENDIAN_H) 15 #include <endian.h> 16 #endif 17 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 htobe32(x) OSSwapHostToBigInt32((x)) 24 #define htole32(x) OSSwapHostToLittleInt32((x)) 25 #define htole64(x) OSSwapHostToLittleInt64((x)) 26 #endif /* __APPLE__ && !HAVE_ENDIAN_H */ 27 28 #if defined(_WIN32) && !defined(HAVE_ENDIAN_H) 29 #include <stdint.h> 30 #include <winsock2.h> 31 #if !defined(_MSC_VER) 32 #include <sys/param.h> 33 #endif 34 #define be16toh(x) ntohs((x)) 35 #define htobe16(x) htons((x)) 36 #define be32toh(x) ntohl((x)) 37 #define htobe32(x) htonl((x)) 38 uint32_t htole32(uint32_t); 39 uint64_t htole64(uint64_t); 40 #endif /* _WIN32 && !HAVE_ENDIAN_H */ 41 42 #if (defined(__FreeBSD__) || defined(__MidnightBSD__)) && !defined(HAVE_ENDIAN_H) 43 #include <sys/endian.h> 44 #endif 45 46 #include <stdlib.h> 47 #include <string.h> 48 49 #if !defined(HAVE_STRLCAT) 50 size_t strlcat(char *, const char *, size_t); 51 #endif 52 53 #if !defined(HAVE_STRLCPY) 54 size_t strlcpy(char *, const char *, size_t); 55 #endif 56 57 #if !defined(HAVE_STRSEP) 58 char *strsep(char **, const char *); 59 #endif 60 61 #if !defined(HAVE_RECALLOCARRAY) 62 void *recallocarray(void *, size_t, size_t, size_t); 63 #endif 64 65 #if !defined(HAVE_EXPLICIT_BZERO) 66 void explicit_bzero(void *, size_t); 67 #endif 68 69 #if !defined(HAVE_FREEZERO) 70 void freezero(void *, size_t); 71 #endif 72 73 #if !defined(HAVE_GETPAGESIZE) 74 int getpagesize(void); 75 #endif 76 77 #if !defined(HAVE_TIMINGSAFE_BCMP) 78 int timingsafe_bcmp(const void *, const void *, size_t); 79 #endif 80 81 #if !defined(HAVE_READPASSPHRASE) 82 #include "readpassphrase.h" 83 #else 84 #include <readpassphrase.h> 85 #endif 86 87 #include <openssl/opensslv.h> 88 89 #if !defined(HAVE_ERR_H) 90 #include "err.h" 91 #else 92 #include <err.h> 93 #endif 94 95 #if !defined(HAVE_GETOPT) 96 #include "getopt.h" 97 #else 98 #include <unistd.h> 99 #endif 100 101 #if !defined(HAVE_GETLINE) 102 #include <stdio.h> 103 ssize_t getline(char **, size_t *, FILE *); 104 #endif 105 106 #if defined(_MSC_VER) 107 #define strerror_r(e, b, l) strerror_s((b), (l), (e)) 108 #endif 109 110 #include "time.h" 111 112 #if !defined(HAVE_POSIX_IOCTL) 113 #define IOCTL_REQ(x) (x) 114 #else 115 #define IOCTL_REQ(x) ((int)(x)) 116 #endif 117 118 #endif /* !_OPENBSD_COMPAT_H */ 119