1 /*- 2 * Copyright (c) 2014 Landon Fuller <landon@landonf.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef _BSD_COMPAT_H 28 #define _BSD_COMPAT_H 29 30 #include "pkg_config.h" 31 32 #ifdef __OpenBSD__ 33 #include "../external/libelf/_elftc.h" 34 35 #ifndef EPROTO 36 #define EPROTO EINTR 37 #endif 38 #endif 39 40 #ifdef HAVE_BSD_SYS_CDEFS_H 41 42 /* Deal with broken __DECONST */ 43 #ifndef __uintptr_t 44 # include <stdint.h> 45 # define __uintptr_t uintptr_t 46 #endif 47 48 #include <bsd/sys/cdefs.h> 49 #endif 50 51 #ifdef HAVE_BSD_STDLIB_H 52 #include <bsd/stdlib.h> 53 #endif 54 55 #ifdef HAVE_BSD_UNISTD_H 56 #include <bsd/unistd.h> 57 #endif 58 59 #ifdef HAVE_BSD_STRING_H 60 #include <bsd/string.h> 61 #endif 62 63 #ifdef HAVE_BSD_STDIO_H 64 #include <bsd/stdio.h> 65 #endif 66 67 #ifdef HAVE_BSD_STLIB_H 68 #include <bsd/stdlib.h> 69 #endif 70 71 #ifdef HAVE_BSD_ERR_H 72 #include <bsd/err.h> 73 #endif 74 75 #ifdef HAVE_BSD_LIBUTIL_H 76 #include <bsd/libutil.h> 77 #endif 78 79 #include <sys/stat.h> 80 #include "endian_util.h" 81 82 #if !HAVE_EACCESS 83 #define eaccess(_p, _m) access(_p, _m) 84 #endif 85 86 #if !HAVE_HUMANIZE_NUMBER 87 #include "humanize_number.h" 88 #endif 89 90 #if !HAVE_CLOSEFROM 91 void closefrom(int lowfd); 92 #endif 93 94 #ifndef AT_FDCWD 95 #define AT_FDCWD -100 96 #endif 97 98 #ifndef AT_EACCESS 99 #define AT_EACCESS 0x100 100 #endif 101 102 #ifndef AT_SYMLINK_NOFOLLOW 103 #define AT_SYMLINK_NOFOLLOW 0x200 104 #endif 105 106 #if !HAVE_FACCESSAT 107 int faccessat(int fd, const char *path, int mode, int flag); 108 #endif 109 110 #if !HAVE_FSTATAT 111 int fstatat(int fd, const char *path, struct stat *buf, int flag); 112 #endif 113 114 #if !HAVE_OPENAT 115 int openat(int fd, const char *path, int flags, ...); 116 #endif 117 118 #if !HAVE_READLINKAT 119 ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize); 120 #endif 121 122 #if !HAVE_UNLINKAT 123 # ifndef AT_REMOVEDIR 124 # define AT_REMOVEDIR 0x800 125 # endif 126 int unlinkat(int fd, const char *path, int flag); 127 #endif 128 129 #if !HAVE_STRTONUM 130 long long strtonum(const char *, long long, long long, const char **); 131 #endif 132 133 #if !HAVE_STRNSTR 134 char * strnstr(const char *s, const char *find, size_t slen); 135 #endif 136 137 #ifndef _PATH_GROUP 138 #define _PATH_GROUP "/etc/group" 139 #endif 140 141 #ifndef __FBSDID 142 #define __FBSDID(x) 143 #endif 144 145 #ifndef EAUTH 146 #define EAUTH 80 147 #endif 148 149 #ifndef ENEEDAUTH 150 #define ENEEDAUTH 81 151 #endif 152 153 #ifndef MAXLOGNAME 154 #define MAXLOGNAME 33 155 #endif 156 157 #ifndef __DECONST 158 #define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 159 #endif 160 161 #ifndef __unused 162 #ifdef __GNUC__ 163 # define __unused __attribute__((__unused__)) 164 #else 165 # define __unused 166 #endif 167 #endif 168 169 #ifndef __unreachable 170 # if defined(__GNUC__) && ((__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)) 171 # define __unreachable() __builtin_unreachable() 172 # elif defined(__clang__) 173 # if __has_builtin(__builtin_unreachable) 174 # define __unreachable() __builtin_unreachable() 175 # endif 176 # else 177 # define __unreachable() ((void)0) 178 # endif 179 #endif 180 181 #if !HAVE_FUNOPEN 182 #if !HAVE_FOPENCOOKIE 183 # error "Your system has neither funopen nor fopencookie, cannot continue" 184 #endif 185 FILE * funopen(const void *cookie, int (*readfn)(void *, char *, int), 186 int (*writefn)(void *, const char *, int), 187 off_t (*seekfn)(void *, off_t, int), int (*closefn)(void *)); 188 #endif 189 190 #if !HAVE_GETPROGNAME 191 #ifdef __GLIBC__ 192 extern char *program_invocation_short_name; 193 # define getprogname() program_invocation_short_name 194 #else 195 # error "Don't know how to replace getprogname()" 196 #endif 197 #endif 198 199 #endif 200