2 * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
21 #include <sys/ioctl.h>
30 #ifdef HAVE_EVENT2_EVENT_H
31 #include <event2/event.h>
32 #include <event2/event_compat.h>
33 #include <event2/event_struct.h>
34 #include <event2/buffer.h>
35 #include <event2/buffer_compat.h>
36 #include <event2/bufferevent.h>
37 #include <event2/bufferevent_struct.h>
38 #include <event2/bufferevent_compat.h>
43 #ifdef HAVE_MALLOC_TRIM
52 #define __attribute__(a)
60 #define __unused __attribute__ ((__unused__))
63 #define __dead __attribute__ ((__noreturn__))
66 #define __packed __attribute__ ((__packed__))
69 #define __weak __attribute__ ((__weak__))
77 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO)
80 #if !defined(FIONREAD) && defined(__sun)
81 #include <sys/filio.h>
87 void err(int, const char *, ...);
88 void errx(int, const char *, ...);
89 void warn(const char *, ...);
90 void warnx(const char *, ...);
98 #define _PATH_BSHELL "/bin/sh"
102 #define _PATH_TMP "/tmp/"
105 #ifndef _PATH_DEVNULL
106 #define _PATH_DEVNULL "/dev/null"
110 #define _PATH_TTY "/dev/tty"
114 #define _PATH_DEV "/dev/"
117 #ifndef _PATH_DEFPATH
118 #define _PATH_DEFPATH "/usr/bin:/bin"
122 #define _PATH_VI "/usr/bin/vi"
126 #define pledge(s, p) (0)
136 #include <inttypes.h>
140 #include <sys/queue.h>
142 #include "compat/queue.h"
146 #include <sys/tree.h>
148 #include "compat/tree.h"
151 #ifdef HAVE_BITSTRING_H
152 #include <bitstring.h>
154 #include "compat/bitstring.h"
157 #ifdef HAVE_LIBUTIL_H
172 #include "compat/vis.h"
178 #include "compat/imsg.h"
181 #ifdef BROKEN_CMSG_FIRSTHDR
183 #define CMSG_FIRSTHDR(mhdr) \
184 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
185 (struct cmsghdr *)(mhdr)->msg_control : \
186 (struct cmsghdr *)NULL)
190 #ifdef _CMSG_DATA_ALIGN
191 #define CMSG_ALIGN _CMSG_DATA_ALIGN
193 #define CMSG_ALIGN(len) (((len) + sizeof(long) - 1) & ~(sizeof(long) - 1))
198 #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
202 #define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
206 #define O_DIRECTORY 0
210 #ifdef FNM_IGNORECASE
211 #define FNM_CASEFOLD FNM_IGNORECASE
213 #define FNM_CASEFOLD 0
226 #define SUN_LEN(sun) (sizeof (sun)->sun_path)
230 #define timercmp(tvp, uvp, cmp) \
231 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
232 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
233 ((tvp)->tv_sec cmp (uvp)->tv_sec))
237 #define timeradd(tvp, uvp, vvp) \
239 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
240 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
241 if ((vvp)->tv_usec >= 1000000) { \
243 (vvp)->tv_usec -= 1000000; \
249 #define timersub(tvp, uvp, vvp) \
251 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
252 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
253 if ((vvp)->tv_usec < 0) { \
255 (vvp)->tv_usec += 1000000; \
261 #define TTY_NAME_MAX 32
264 #ifndef HOST_NAME_MAX
265 #define HOST_NAME_MAX 255
268 #ifndef CLOCK_REALTIME
269 #define CLOCK_REALTIME 0
271 #ifndef CLOCK_MONOTONIC
272 #define CLOCK_MONOTONIC CLOCK_REALTIME
279 #define flock(fd, op) (0)
282 #ifndef HAVE_EXPLICIT_BZERO
283 /* explicit_bzero.c */
284 void explicit_bzero(void *, size_t);
287 #ifndef HAVE_GETDTABLECOUNT
288 /* getdtablecount.c */
289 int getdtablecount(void);
292 #ifndef HAVE_CLOSEFROM
297 #ifndef HAVE_STRCASESTR
299 char *strcasestr(const char *, const char *);
304 char *strsep(char **, const char *);
307 #ifndef HAVE_STRTONUM
309 long long strtonum(const char *, long long, long long, const char **);
314 size_t strlcpy(char *, const char *, size_t);
319 size_t strlcat(char *, const char *, size_t);
324 size_t strnlen(const char *, size_t);
329 char *strndup(const char *, size_t);
334 void *memmem(const void *, size_t, const void *, size_t);
337 #ifndef HAVE_GETPEEREID
339 int getpeereid(int, uid_t
*, gid_t
*);
344 int daemon(int, int);
347 #ifndef HAVE_GETPROGNAME
349 const char *getprogname(void);
352 #ifndef HAVE_SETPROCTITLE
354 void setproctitle(const char *, ...);
357 #ifndef HAVE_CLOCK_GETTIME
358 /* clock_gettime.c */
359 int clock_gettime(int, struct timespec
*);
362 #ifndef HAVE_B64_NTOP
366 int b64_ntop(const char *, size_t, char *, size_t);
367 int b64_pton(const char *, u_char
*, size_t);
370 #ifndef HAVE_FDFORKPTY
373 pid_t
fdforkpty(int, int *, char *, struct termios
*,
379 pid_t
forkpty(int *, char *, struct termios
*, struct winsize
*);
382 #ifndef HAVE_ASPRINTF
384 int asprintf(char **, const char *, ...);
385 int vasprintf(char **, const char *, va_list);
390 char *fgetln(FILE *, size_t *);
395 ssize_t
getline(char **, size_t *, FILE *);
400 int setenv(const char *, const char *, int);
401 int unsetenv(const char *);
404 #ifndef HAVE_CFMAKERAW
406 void cfmakeraw(struct termios
*);
409 #ifndef HAVE_FREEZERO
411 void freezero(void *, size_t);
414 #ifndef HAVE_REALLOCARRAY
416 void *reallocarray(void *, size_t, size_t);
419 #ifndef HAVE_RECALLOCARRAY
420 /* recallocarray.c */
421 void *recallocarray(void *, size_t, size_t, size_t);
426 int systemd_activated(void);
427 int systemd_create_socket(int, char **);
428 int systemd_move_pid_to_new_cgroup(pid_t
, char **);
433 int utf8proc_wcwidth(wchar_t);
434 int utf8proc_mbtowc(wchar_t *, const char *, size_t);
435 int utf8proc_wctomb(char *, wchar_t);
440 #define main __weak main
444 extern int BSDopterr
;
445 extern int BSDoptind
;
446 extern int BSDoptopt
;
447 extern int BSDoptreset
;
448 extern char *BSDoptarg
;
449 int BSDgetopt(int, char *const *, const char *);
450 #define getopt(ac, av, o) BSDgetopt(ac, av, o)
451 #define opterr BSDopterr
452 #define optind BSDoptind
453 #define optopt BSDoptopt
454 #define optreset BSDoptreset
455 #define optarg BSDoptarg
457 #endif /* COMPAT_H */