openbsd-compat.h revision 162852
1162852Sdes/* $Id: openbsd-compat.h,v 1.42 2006/09/03 12:44:50 dtucker Exp $ */
298937Sdes
3124208Sdes/*
4124208Sdes * Copyright (c) 1999-2003 Damien Miller.  All rights reserved.
5124208Sdes * Copyright (c) 2003 Ben Lindstrom. All rights reserved.
6124208Sdes * Copyright (c) 2002 Tim Rice.  All rights reserved.
7124208Sdes *
8124208Sdes * Redistribution and use in source and binary forms, with or without
9124208Sdes * modification, are permitted provided that the following conditions
10124208Sdes * are met:
11124208Sdes * 1. Redistributions of source code must retain the above copyright
12124208Sdes *    notice, this list of conditions and the following disclaimer.
13124208Sdes * 2. Redistributions in binary form must reproduce the above copyright
14124208Sdes *    notice, this list of conditions and the following disclaimer in the
15124208Sdes *    documentation and/or other materials provided with the distribution.
16124208Sdes *
17124208Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18124208Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19124208Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20124208Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21124208Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22124208Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23124208Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24124208Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25124208Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26124208Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27124208Sdes */
2898937Sdes
29124208Sdes#ifndef _OPENBSD_COMPAT_H
30124208Sdes#define _OPENBSD_COMPAT_H
3198937Sdes
32124208Sdes#include "includes.h"
33124208Sdes
34162852Sdes#include <sys/types.h>
35162852Sdes#include <pwd.h>
36162852Sdes
37162852Sdes#include <sys/socket.h>
38162852Sdes
3998937Sdes/* OpenBSD function replacements */
4098937Sdes#include "base64.h"
4198937Sdes#include "sigact.h"
4298937Sdes#include "glob.h"
4398937Sdes#include "readpassphrase.h"
44113908Sdes#include "vis.h"
45124208Sdes#include "getrrsetbyname.h"
46162852Sdes#include "sha2.h"
4798937Sdes
48124208Sdes#ifndef HAVE_BASENAME
49124208Sdeschar *basename(const char *path);
50124208Sdes#endif
51124208Sdes
52124208Sdes#ifndef HAVE_BINDRESVPORT_SA
53124208Sdesint bindresvport_sa(int sd, struct sockaddr *sa);
54124208Sdes#endif
55124208Sdes
56137015Sdes#ifndef HAVE_CLOSEFROM
57137015Sdesvoid closefrom(int);
58137015Sdes#endif
59137015Sdes
60124208Sdes#ifndef HAVE_GETCWD
61124208Sdeschar *getcwd(char *pt, size_t size);
62124208Sdes#endif
63124208Sdes
64124208Sdes#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
65124208Sdeschar *realpath(const char *path, char *resolved);
66124208Sdes#endif
67124208Sdes
68124208Sdes#ifndef HAVE_RRESVPORT_AF
69124208Sdesint rresvport_af(int *alport, sa_family_t af);
70124208Sdes#endif
71124208Sdes
72124208Sdes#ifndef HAVE_STRLCPY
73124208Sdes/* #include <sys/types.h> XXX Still needed? */
74124208Sdessize_t strlcpy(char *dst, const char *src, size_t siz);
75124208Sdes#endif
76124208Sdes
77124208Sdes#ifndef HAVE_STRLCAT
78124208Sdes/* #include <sys/types.h> XXX Still needed? */
79124208Sdessize_t strlcat(char *dst, const char *src, size_t siz);
80124208Sdes#endif
81124208Sdes
82124208Sdes#ifndef HAVE_SETENV
83124208Sdesint setenv(register const char *name, register const char *value, int rewrite);
84124208Sdes#endif
85124208Sdes
86124208Sdes#ifndef HAVE_STRMODE
87124208Sdesvoid strmode(int mode, char *p);
88124208Sdes#endif
89124208Sdes
90124208Sdes#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
91124208Sdesint mkstemps(char *path, int slen);
92124208Sdesint mkstemp(char *path);
93124208Sdeschar *mkdtemp(char *path);
94124208Sdes#endif
95124208Sdes
96124208Sdes#ifndef HAVE_DAEMON
97124208Sdesint daemon(int nochdir, int noclose);
98124208Sdes#endif
99124208Sdes
100124208Sdes#ifndef HAVE_DIRNAME
101124208Sdeschar *dirname(const char *path);
102124208Sdes#endif
103124208Sdes
104124208Sdes#if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA)
105124208Sdeschar *inet_ntoa(struct in_addr in);
106124208Sdes#endif
107124208Sdes
108124208Sdes#ifndef HAVE_INET_NTOP
109124208Sdesconst char *inet_ntop(int af, const void *src, char *dst, size_t size);
110124208Sdes#endif
111124208Sdes
112124208Sdes#ifndef HAVE_INET_ATON
113124208Sdesint inet_aton(const char *cp, struct in_addr *addr);
114124208Sdes#endif
115124208Sdes
116124208Sdes#ifndef HAVE_STRSEP
117124208Sdeschar *strsep(char **stringp, const char *delim);
118124208Sdes#endif
119124208Sdes
120124208Sdes#ifndef HAVE_SETPROCTITLE
121124208Sdesvoid setproctitle(const char *fmt, ...);
122124208Sdesvoid compat_init_setproctitle(int argc, char *argv[]);
123124208Sdes#endif
124124208Sdes
125124208Sdes#ifndef HAVE_GETGROUPLIST
126124208Sdes/* #include <grp.h> XXXX Still needed ? */
127124208Sdesint getgrouplist(const char *, gid_t, gid_t *, int *);
128124208Sdes#endif
129124208Sdes
130124208Sdes#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
131124208Sdesint BSDgetopt(int argc, char * const *argv, const char *opts);
132124208Sdes#endif
133124208Sdes
134162852Sdes#if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0
135162852Sdes# include <sys/types.h>
136162852Sdes# include <sys/uio.h>
137162852Sdesint writev(int, struct iovec *, int);
138162852Sdes#endif
139124208Sdes
14098937Sdes/* Home grown routines */
14198937Sdes#include "bsd-misc.h"
14298937Sdes#include "bsd-waitpid.h"
14398937Sdes
144124208Sdes#ifndef HAVE_GETPEEREID
145124208Sdesint getpeereid(int , uid_t *, gid_t *);
146124208Sdes#endif
147124208Sdes
148124208Sdes#ifndef HAVE_ARC4RANDOM
149124208Sdesunsigned int arc4random(void);
150124208Sdesvoid arc4random_stir(void);
151124208Sdes#endif /* !HAVE_ARC4RANDOM */
152124208Sdes
153157016Sdes#ifndef HAVE_ASPRINTF
154157016Sdesint asprintf(char **, const char *, ...);
155157016Sdes#endif
156157016Sdes
157126274Sdes#ifndef HAVE_OPENPTY
158162852Sdes# include <sys/ioctl.h>	/* for struct winsize */
159126274Sdesint openpty(int *, int *, char *, struct termios *, struct winsize *);
160126274Sdes#endif /* HAVE_OPENPTY */
161124208Sdes
162124208Sdes/* #include <sys/types.h> XXX needed? For size_t */
163124208Sdes
164124208Sdes#ifndef HAVE_SNPRINTF
165162852Sdesint snprintf(char *, size_t, SNPRINTF_CONST char *, ...);
166124208Sdes#endif
167124208Sdes
168157016Sdes#ifndef HAVE_STRTOLL
169157016Sdeslong long strtoll(const char *, char **, int);
170157016Sdes#endif
171157016Sdes
172149749Sdes#ifndef HAVE_STRTONUM
173149749Sdeslong long strtonum(const char *, long long, long long, const char **);
174149749Sdes#endif
175149749Sdes
176162852Sdes#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
177162852Sdes# include <stdarg.h>
178162852Sdes#endif
179162852Sdes
180157016Sdes#ifndef HAVE_VASPRINTF
181157016Sdesint vasprintf(char **, const char *, va_list);
182157016Sdes#endif
183157016Sdes
184124208Sdes#ifndef HAVE_VSNPRINTF
185124208Sdesint vsnprintf(char *, size_t, const char *, va_list);
186124208Sdes#endif
187124208Sdes
188124208Sdesvoid *xmmap(size_t size);
189124208Sdeschar *xcrypt(const char *password, const char *salt);
190124208Sdeschar *shadow_pw(struct passwd *pw);
191124208Sdes
19298937Sdes/* rfc2553 socket API replacements */
193124208Sdes#include "fake-rfc2553.h"
19498937Sdes
19598937Sdes/* Routines for a single OS platform */
19698937Sdes#include "bsd-cray.h"
197124208Sdes#include "bsd-cygwin_util.h"
198162852Sdes
199162852Sdes#include "port-aix.h"
20098937Sdes#include "port-irix.h"
201162852Sdes#include "port-linux.h"
202162852Sdes#include "port-solaris.h"
203162852Sdes#include "port-tun.h"
204149749Sdes#include "port-uw.h"
20598937Sdes
206124208Sdes#endif /* _OPENBSD_COMPAT_H */
207