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 # include <login_cap.h>
53 # define login_getpwclass(pw) login_getclass(pw->pw_class)
57 char *basename(
const char *path);
60 #ifndef HAVE_BINDRESVPORT_SA
61 int bindresvport_sa(
int sd,
struct sockaddr *sa);
64 #ifndef HAVE_CLOSEFROM
68 #if defined(HAVE_DECL_FTRUNCATE) && HAVE_DECL_FTRUNCATE == 0
69 int ftruncate(
int filedes, off_t length);
74 ssize_t getline(
char **,
size_t *, FILE *);
77 #ifndef HAVE_GETPAGESIZE
78 int getpagesize(
void);
82 char *getcwd(
char *pt,
size_t size);
86 int killpg(pid_t,
int);
89 #if defined(HAVE_DECL_MEMMEM) && HAVE_DECL_MEMMEM == 0
90 void *memmem(
const void *,
size_t,
const void *,
size_t);
93 #ifndef HAVE_REALLOCARRAY
94 void *reallocarray(
void *,
size_t,
size_t);
97 #ifndef HAVE_RECALLOCARRAY
98 void *recallocarray(
void *,
size_t,
size_t,
size_t);
101 #ifndef HAVE_RRESVPORT_AF
102 int rresvport_af(
int *alport, sa_family_t af);
106 size_t strlcpy(
char *dst,
const char *src,
size_t siz);
110 size_t strlcat(
char *dst,
const char *src,
size_t siz);
113 #ifndef HAVE_STRCASESTR
114 char *strcasestr(
const char *,
const char *);
118 size_t strnlen(
const char *,
size_t);
122 char *strndup(
const char *s,
size_t n);
126 int setenv(
register const char *name,
register const char *value,
int rewrite);
130 void strmode(
int mode,
char *p);
133 #ifndef HAVE_STRPTIME
135 char *strptime(
const char *buf,
const char *fmt,
struct tm *tm);
138 #if !defined(HAVE_MKDTEMP)
139 int mkstemps(
char *path,
int slen);
140 int mkstemp(
char *path);
141 char *mkdtemp(
char *path);
144 #define mkstemp(x) _ssh_mkstemp(x)
145 int _ssh_mkstemp(
char *);
148 int daemon(
int nochdir,
int noclose);
152 char *dirname(
const char *path);
155 #ifndef HAVE_FMT_SCALED
156 #define FMT_SCALED_STRSIZE 7
157 int fmt_scaled(
long long number,
char *result);
160 #ifndef HAVE_SCAN_SCALED
161 int scan_scaled(
char *,
long long *);
164 #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA)
165 char *inet_ntoa(
struct in_addr in);
168 #ifndef HAVE_INET_NTOP
169 const char *inet_ntop(
int af,
const void *src,
char *dst, socklen_t size);
172 #ifndef HAVE_INET_ATON
173 int inet_aton(
const char *cp,
struct in_addr *addr);
177 char *strsep(
char **stringp,
const char *delim);
180 #ifndef HAVE_SETPROCTITLE
181 void setproctitle(
const char *fmt, ...);
182 void compat_init_setproctitle(
int argc,
char *argv[]);
185 #ifndef HAVE_GETGROUPLIST
186 int getgrouplist(
const char *, gid_t, gid_t *,
int *);
189 #if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
190 int BSDgetopt(
int argc,
char *
const *argv,
const char *opts);
191 #include "openbsd-compat/getopt.h"
194 #if ((defined(HAVE_DECL_READV) && HAVE_DECL_READV == 0) || \
195 (defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0))
196 # include <sys/types.h>
197 # include <sys/uio.h>
199 # if defined(HAVE_DECL_READV) && HAVE_DECL_READV == 0
200 int readv(
int,
struct iovec *,
int);
203 # if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0
204 int writev(
int,
struct iovec *,
int);
209 #include "bsd-signal.h"
210 #include "bsd-misc.h"
211 #include "bsd-setres_id.h"
212 #include "bsd-statvfs.h"
213 #include "bsd-waitpid.h"
214 #include "bsd-poll.h"
216 #if defined(HAVE_DECL_GETPEEREID) && HAVE_DECL_GETPEEREID == 0
217 int getpeereid(
int , uid_t *, gid_t *);
220 #ifndef HAVE_ARC4RANDOM
221 uint32_t arc4random(
void);
224 #ifndef HAVE_ARC4RANDOM_BUF
225 void arc4random_buf(
void *,
size_t);
228 #ifndef HAVE_ARC4RANDOM_STIR
229 # define arc4random_stir()
232 #ifndef HAVE_ARC4RANDOM_UNIFORM
233 uint32_t arc4random_uniform(uint32_t);
236 #ifndef HAVE_ASPRINTF
237 int asprintf(
char **,
const char *, ...);
241 # include <sys/ioctl.h>
242 int openpty(
int *,
int *,
char *,
struct termios *,
struct winsize *);
245 #ifndef HAVE_SNPRINTF
246 int snprintf(
char *,
size_t, SNPRINTF_CONST
char *, ...);
250 long long strtoll(
const char *,
char **,
int);
254 unsigned long strtoul(
const char *,
char **,
int);
257 #ifndef HAVE_STRTOULL
258 unsigned long long strtoull(
const char *,
char **,
int);
261 #ifndef HAVE_STRTONUM
262 long long strtonum(
const char *,
long long,
long long,
const char **);
267 # define mblen(x, y) (1)
271 # define wcwidth(x) (((x) >= 0x20 && (x) <= 0x7e) ? 1 : -1)
273 # undef HAVE_NL_LANGINFO
275 # undef HAVE_LANGINFO_H
278 #ifndef HAVE_NL_LANGINFO
279 # define nl_langinfo(x) ""
283 int mbtowc(
wchar_t *,
const char*,
size_t);
286 #if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
297 # define VA_COPY(dest, src) va_copy(dest, src)
299 # ifdef HAVE___VA_COPY
300 # define VA_COPY(dest, src) __va_copy(dest, src)
302 # define VA_COPY(dest, src) (dest) = (src)
307 #ifndef HAVE_VASPRINTF
308 int vasprintf(
char **,
const char *, va_list);
311 #ifndef HAVE_VSNPRINTF
312 int vsnprintf(
char *,
size_t,
const char *, va_list);
315 #ifndef HAVE_USER_FROM_UID
316 char *user_from_uid(uid_t,
int);
319 #ifndef HAVE_GROUP_FROM_GID
320 char *group_from_gid(gid_t,
int);
323 #ifndef HAVE_TIMINGSAFE_BCMP
324 int timingsafe_bcmp(
const void *,
const void *,
size_t);
327 #ifndef HAVE_BCRYPT_PBKDF
328 int bcrypt_pbkdf(
const char *,
size_t,
const uint8_t *,
size_t,
329 uint8_t *,
size_t,
unsigned int);
332 #ifndef HAVE_EXPLICIT_BZERO
333 void explicit_bzero(
void *p,
size_t n);
336 #ifndef HAVE_FREEZERO
337 void freezero(
void *,
size_t);
340 #ifndef HAVE_LOCALTIME_R
341 struct tm *localtime_r(
const time_t *,
struct tm *);
346 time_t timegm(
struct tm *);
349 char *xcrypt(
const char *password,
const char *salt);
350 char *shadow_pw(
struct passwd *pw);
353 #include "fake-rfc2553.h"
356 #include "bsd-cygwin_util.h"
358 #include "port-aix.h"
359 #include "port-irix.h"
360 #include "port-linux.h"
361 #include "port-solaris.h"
362 #include "port-net.h"
366 #if defined(HAVE_FEATURES_H) && defined(_FORTIFY_SOURCE)
367 # include <features.h>
368 # if defined(__GNU_LIBRARY__) && defined(__GLIBC_PREREQ)
369 # if __GLIBC_PREREQ(2, 15) && (_FORTIFY_SOURCE > 0)
370 # include <sys/socket.h>
373 # define FD_SET(n, set) kludge_FD_SET(n, set)
374 # define FD_ISSET(n, set) kludge_FD_ISSET(n, set)
375 void kludge_FD_SET(
int, fd_set *);
376 int kludge_FD_ISSET(
int, fd_set *);