27 #ifndef _OPENBSD_COMPAT_H
28 #define _OPENBSD_COMPAT_H
32 #include <sys/types.h>
35 #include <sys/socket.h>
42 #include "readpassphrase.h"
44 #include "getrrsetbyname.h"
51 #if defined(HAVE_LOGIN_CAP) && !defined(HAVE_LOGIN_GETPWCLASS)
52 # define login_getpwclass(pw) login_getclass(pw->pw_class)
56 char *basename(
const char *path);
59 #ifndef HAVE_BINDRESVPORT_SA
60 int bindresvport_sa(
int sd,
struct sockaddr *sa);
63 #ifndef HAVE_CLOSEFROM
69 ssize_t getline(
char **,
size_t *, FILE *);
72 #ifndef HAVE_GETPAGESIZE
73 int getpagesize(
void);
77 char *getcwd(
char *pt,
size_t size);
80 #if defined(HAVE_DECL_MEMMEM) && HAVE_DECL_MEMMEM == 0
81 void *memmem(
const void *,
size_t,
const void *,
size_t);
84 #ifndef HAVE_REALLOCARRAY
85 void *reallocarray(
void *,
size_t,
size_t);
88 #ifndef HAVE_RECALLOCARRAY
89 void *recallocarray(
void *,
size_t,
size_t,
size_t);
92 #ifndef HAVE_RRESVPORT_AF
93 int rresvport_af(
int *alport, sa_family_t af);
97 size_t strlcpy(
char *dst,
const char *src,
size_t siz);
101 size_t strlcat(
char *dst,
const char *src,
size_t siz);
104 #ifndef HAVE_STRCASESTR
105 char *strcasestr(
const char *,
const char *);
109 size_t strnlen(
const char *,
size_t);
113 char *strndup(
const char *s,
size_t n);
117 int setenv(
register const char *name,
register const char *value,
int rewrite);
121 void strmode(
int mode,
char *p);
124 #ifndef HAVE_STRPTIME
126 char *strptime(
const char *buf,
const char *fmt,
struct tm *tm);
129 #if !defined(HAVE_MKDTEMP)
130 int mkstemps(
char *path,
int slen);
131 int mkstemp(
char *path);
132 char *mkdtemp(
char *path);
136 int daemon(
int nochdir,
int noclose);
140 char *dirname(
const char *path);
143 #ifndef HAVE_FMT_SCALED
144 #define FMT_SCALED_STRSIZE 7
145 int fmt_scaled(
long long number,
char *result);
148 #ifndef HAVE_SCAN_SCALED
149 int scan_scaled(
char *,
long long *);
152 #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA)
153 char *inet_ntoa(
struct in_addr in);
156 #ifndef HAVE_INET_NTOP
157 const char *inet_ntop(
int af,
const void *src,
char *dst, socklen_t size);
160 #ifndef HAVE_INET_ATON
161 int inet_aton(
const char *cp,
struct in_addr *addr);
165 char *strsep(
char **stringp,
const char *delim);
168 #ifndef HAVE_SETPROCTITLE
169 void setproctitle(
const char *fmt, ...);
170 void compat_init_setproctitle(
int argc,
char *argv[]);
173 #ifndef HAVE_GETGROUPLIST
174 int getgrouplist(
const char *, gid_t, gid_t *,
int *);
177 #if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
178 int BSDgetopt(
int argc,
char *
const *argv,
const char *opts);
179 #include "openbsd-compat/getopt.h"
182 #if ((defined(HAVE_DECL_READV) && HAVE_DECL_READV == 0) || \
183 (defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0))
184 # include <sys/types.h>
185 # include <sys/uio.h>
187 # if defined(HAVE_DECL_READV) && HAVE_DECL_READV == 0
188 int readv(
int,
struct iovec *,
int);
191 # if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0
192 int writev(
int,
struct iovec *,
int);
197 #include "bsd-misc.h"
198 #include "bsd-setres_id.h"
199 #include "bsd-signal.h"
200 #include "bsd-statvfs.h"
201 #include "bsd-waitpid.h"
202 #include "bsd-poll.h"
204 #if defined(HAVE_DECL_GETPEEREID) && HAVE_DECL_GETPEEREID == 0
205 int getpeereid(
int , uid_t *, gid_t *);
208 #ifdef HAVE_ARC4RANDOM
209 # ifndef HAVE_ARC4RANDOM_STIR
210 # define arc4random_stir()
213 unsigned int arc4random(
void);
214 void arc4random_stir(
void);
217 #ifndef HAVE_ARC4RANDOM_BUF
218 void arc4random_buf(
void *,
size_t);
221 #ifndef HAVE_ARC4RANDOM_UNIFORM
222 u_int32_t arc4random_uniform(u_int32_t);
225 #ifndef HAVE_ASPRINTF
226 int asprintf(
char **,
const char *, ...);
230 # include <sys/ioctl.h>
231 int openpty(
int *,
int *,
char *,
struct termios *,
struct winsize *);
234 #ifndef HAVE_SNPRINTF
235 int snprintf(
char *,
size_t, SNPRINTF_CONST
char *, ...);
239 long long strtoll(
const char *,
char **,
int);
243 unsigned long strtoul(
const char *,
char **,
int);
246 #ifndef HAVE_STRTOULL
247 unsigned long long strtoull(
const char *,
char **,
int);
250 #ifndef HAVE_STRTONUM
251 long long strtonum(
const char *,
long long,
long long,
const char **);
256 # define mblen(x, y) (1)
260 # define wcwidth(x) (((x) >= 0x20 && (x) <= 0x7e) ? 1 : -1)
262 # undef HAVE_NL_LANGINFO
264 # undef HAVE_LANGINFO_H
267 #ifndef HAVE_NL_LANGINFO
268 # define nl_langinfo(x) ""
272 int mbtowc(
wchar_t *,
const char*,
size_t);
275 #if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
286 # define VA_COPY(dest, src) va_copy(dest, src)
288 # ifdef HAVE___VA_COPY
289 # define VA_COPY(dest, src) __va_copy(dest, src)
291 # define VA_COPY(dest, src) (dest) = (src)
296 #ifndef HAVE_VASPRINTF
297 int vasprintf(
char **,
const char *, va_list);
300 #ifndef HAVE_VSNPRINTF
301 int vsnprintf(
char *,
size_t,
const char *, va_list);
304 #ifndef HAVE_USER_FROM_UID
305 char *user_from_uid(uid_t,
int);
308 #ifndef HAVE_GROUP_FROM_GID
309 char *group_from_gid(gid_t,
int);
312 #ifndef HAVE_TIMINGSAFE_BCMP
313 int timingsafe_bcmp(
const void *,
const void *,
size_t);
316 #ifndef HAVE_BCRYPT_PBKDF
317 int bcrypt_pbkdf(
const char *,
size_t,
const u_int8_t *,
size_t,
318 u_int8_t *,
size_t,
unsigned int);
321 #ifndef HAVE_EXPLICIT_BZERO
322 void explicit_bzero(
void *p,
size_t n);
325 #ifndef HAVE_FREEZERO
326 void freezero(
void *,
size_t);
329 #ifndef HAVE_LOCALTIME_R
330 struct tm *localtime_r(
const time_t *,
struct tm *);
333 char *xcrypt(
const char *password,
const char *salt);
334 char *shadow_pw(
struct passwd *pw);
337 #include "fake-rfc2553.h"
340 #include "bsd-cygwin_util.h"
342 #include "port-aix.h"
343 #include "port-irix.h"
344 #include "port-linux.h"
345 #include "port-solaris.h"
346 #include "port-net.h"
350 #if defined(HAVE_FEATURES_H) && defined(_FORTIFY_SOURCE)
351 # include <features.h>
352 # if defined(__GNU_LIBRARY__) && defined(__GLIBC_PREREQ)
353 # if __GLIBC_PREREQ(2, 15) && (_FORTIFY_SOURCE > 0)
354 # include <sys/socket.h>
357 # define FD_SET(n, set) kludge_FD_SET(n, set)
358 # define FD_ISSET(n, set) kludge_FD_ISSET(n, set)
359 void kludge_FD_SET(
int, fd_set *);
360 int kludge_FD_ISSET(
int, fd_set *);