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
70 ssize_t getline(
char **,
size_t *, FILE *);
73 #ifndef HAVE_GETPAGESIZE
74 int getpagesize(
void);
78 char *getcwd(
char *pt,
size_t size);
81 #if defined(HAVE_DECL_MEMMEM) && HAVE_DECL_MEMMEM == 0
82 void *memmem(
const void *,
size_t,
const void *,
size_t);
85 #ifndef HAVE_REALLOCARRAY
86 void *reallocarray(
void *,
size_t,
size_t);
89 #ifndef HAVE_RECALLOCARRAY
90 void *recallocarray(
void *,
size_t,
size_t,
size_t);
93 #ifndef HAVE_RRESVPORT_AF
94 int rresvport_af(
int *alport, sa_family_t af);
98 size_t strlcpy(
char *dst,
const char *src,
size_t siz);
102 size_t strlcat(
char *dst,
const char *src,
size_t siz);
105 #ifndef HAVE_STRCASESTR
106 char *strcasestr(
const char *,
const char *);
110 size_t strnlen(
const char *,
size_t);
114 char *strndup(
const char *s,
size_t n);
118 int setenv(
register const char *name,
register const char *value,
int rewrite);
122 void strmode(
int mode,
char *p);
125 #ifndef HAVE_STRPTIME
127 char *strptime(
const char *buf,
const char *fmt,
struct tm *tm);
130 #if !defined(HAVE_MKDTEMP)
131 int mkstemps(
char *path,
int slen);
132 int mkstemp(
char *path);
133 char *mkdtemp(
char *path);
137 int daemon(
int nochdir,
int noclose);
141 char *dirname(
const char *path);
144 #ifndef HAVE_FMT_SCALED
145 #define FMT_SCALED_STRSIZE 7
146 int fmt_scaled(
long long number,
char *result);
149 #ifndef HAVE_SCAN_SCALED
150 int scan_scaled(
char *,
long long *);
153 #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA)
154 char *inet_ntoa(
struct in_addr in);
157 #ifndef HAVE_INET_NTOP
158 const char *inet_ntop(
int af,
const void *src,
char *dst, socklen_t size);
161 #ifndef HAVE_INET_ATON
162 int inet_aton(
const char *cp,
struct in_addr *addr);
166 char *strsep(
char **stringp,
const char *delim);
169 #ifndef HAVE_SETPROCTITLE
170 void setproctitle(
const char *fmt, ...);
171 void compat_init_setproctitle(
int argc,
char *argv[]);
174 #ifndef HAVE_GETGROUPLIST
175 int getgrouplist(
const char *, gid_t, gid_t *,
int *);
178 #if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
179 int BSDgetopt(
int argc,
char *
const *argv,
const char *opts);
180 #include "openbsd-compat/getopt.h"
183 #if ((defined(HAVE_DECL_READV) && HAVE_DECL_READV == 0) || \
184 (defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0))
185 # include <sys/types.h>
186 # include <sys/uio.h>
188 # if defined(HAVE_DECL_READV) && HAVE_DECL_READV == 0
189 int readv(
int,
struct iovec *,
int);
192 # if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0
193 int writev(
int,
struct iovec *,
int);
198 #include "bsd-signal.h"
199 #include "bsd-misc.h"
200 #include "bsd-setres_id.h"
201 #include "bsd-statvfs.h"
202 #include "bsd-waitpid.h"
203 #include "bsd-poll.h"
205 #if defined(HAVE_DECL_GETPEEREID) && HAVE_DECL_GETPEEREID == 0
206 int getpeereid(
int , uid_t *, gid_t *);
209 #ifdef HAVE_ARC4RANDOM
210 # ifndef HAVE_ARC4RANDOM_STIR
211 # define arc4random_stir()
214 unsigned int arc4random(
void);
215 void arc4random_stir(
void);
218 #ifndef HAVE_ARC4RANDOM_BUF
219 void arc4random_buf(
void *,
size_t);
222 #ifndef HAVE_ARC4RANDOM_UNIFORM
223 u_int32_t arc4random_uniform(u_int32_t);
226 #ifndef HAVE_ASPRINTF
227 int asprintf(
char **,
const char *, ...);
231 # include <sys/ioctl.h>
232 int openpty(
int *,
int *,
char *,
struct termios *,
struct winsize *);
235 #ifndef HAVE_SNPRINTF
236 int snprintf(
char *,
size_t, SNPRINTF_CONST
char *, ...);
240 long long strtoll(
const char *,
char **,
int);
244 unsigned long strtoul(
const char *,
char **,
int);
247 #ifndef HAVE_STRTOULL
248 unsigned long long strtoull(
const char *,
char **,
int);
251 #ifndef HAVE_STRTONUM
252 long long strtonum(
const char *,
long long,
long long,
const char **);
257 # define mblen(x, y) (1)
261 # define wcwidth(x) (((x) >= 0x20 && (x) <= 0x7e) ? 1 : -1)
263 # undef HAVE_NL_LANGINFO
265 # undef HAVE_LANGINFO_H
268 #ifndef HAVE_NL_LANGINFO
269 # define nl_langinfo(x) ""
273 int mbtowc(
wchar_t *,
const char*,
size_t);
276 #if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
287 # define VA_COPY(dest, src) va_copy(dest, src)
289 # ifdef HAVE___VA_COPY
290 # define VA_COPY(dest, src) __va_copy(dest, src)
292 # define VA_COPY(dest, src) (dest) = (src)
297 #ifndef HAVE_VASPRINTF
298 int vasprintf(
char **,
const char *, va_list);
301 #ifndef HAVE_VSNPRINTF
302 int vsnprintf(
char *,
size_t,
const char *, va_list);
305 #ifndef HAVE_USER_FROM_UID
306 char *user_from_uid(uid_t,
int);
309 #ifndef HAVE_GROUP_FROM_GID
310 char *group_from_gid(gid_t,
int);
313 #ifndef HAVE_TIMINGSAFE_BCMP
314 int timingsafe_bcmp(
const void *,
const void *,
size_t);
317 #ifndef HAVE_BCRYPT_PBKDF
318 int bcrypt_pbkdf(
const char *,
size_t,
const u_int8_t *,
size_t,
319 u_int8_t *,
size_t,
unsigned int);
322 #ifndef HAVE_EXPLICIT_BZERO
323 void explicit_bzero(
void *p,
size_t n);
326 #ifndef HAVE_FREEZERO
327 void freezero(
void *,
size_t);
330 #ifndef HAVE_LOCALTIME_R
331 struct tm *localtime_r(
const time_t *,
struct tm *);
334 char *xcrypt(
const char *password,
const char *salt);
335 char *shadow_pw(
struct passwd *pw);
338 #include "fake-rfc2553.h"
341 #include "bsd-cygwin_util.h"
343 #include "port-aix.h"
344 #include "port-irix.h"
345 #include "port-linux.h"
346 #include "port-solaris.h"
347 #include "port-net.h"
351 #if defined(HAVE_FEATURES_H) && defined(_FORTIFY_SOURCE)
352 # include <features.h>
353 # if defined(__GNU_LIBRARY__) && defined(__GLIBC_PREREQ)
354 # if __GLIBC_PREREQ(2, 15) && (_FORTIFY_SOURCE > 0)
355 # include <sys/socket.h>
358 # define FD_SET(n, set) kludge_FD_SET(n, set)
359 # define FD_ISSET(n, set) kludge_FD_ISSET(n, set)
360 void kludge_FD_SET(
int, fd_set *);
361 int kludge_FD_ISSET(
int, fd_set *);