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_GETDTABLESIZE
293 /* getdtablesize.c */
294 int getdtablesize(void);
297 #ifndef HAVE_CLOSEFROM
302 #ifndef HAVE_STRCASESTR
304 char *strcasestr(const char *, const char *);
309 char *strsep(char **, const char *);
312 #ifndef HAVE_STRTONUM
314 long long strtonum(const char *, long long, long long, const char **);
319 size_t strlcpy(char *, const char *, size_t);
324 size_t strlcat(char *, const char *, size_t);
329 size_t strnlen(const char *, size_t);
334 char *strndup(const char *, size_t);
339 void *memmem(const void *, size_t, const void *, size_t);
345 uint64_t htonll(uint64_t);
351 uint64_t ntohll(uint64_t);
354 #ifndef HAVE_GETPEEREID
356 int getpeereid(int, uid_t
*, gid_t
*);
361 int daemon(int, int);
364 #ifndef HAVE_GETPROGNAME
366 const char *getprogname(void);
369 #ifndef HAVE_SETPROCTITLE
371 void setproctitle(const char *, ...);
374 #ifndef HAVE_CLOCK_GETTIME
375 /* clock_gettime.c */
376 int clock_gettime(int, struct timespec
*);
379 #ifndef HAVE_B64_NTOP
383 int b64_ntop(const char *, size_t, char *, size_t);
384 int b64_pton(const char *, u_char
*, size_t);
387 #ifndef HAVE_FDFORKPTY
390 pid_t
fdforkpty(int, int *, char *, struct termios
*,
396 pid_t
forkpty(int *, char *, struct termios
*, struct winsize
*);
399 #ifndef HAVE_ASPRINTF
401 int asprintf(char **, const char *, ...);
402 int vasprintf(char **, const char *, va_list);
407 char *fgetln(FILE *, size_t *);
412 ssize_t
getline(char **, size_t *, FILE *);
417 int setenv(const char *, const char *, int);
418 int unsetenv(const char *);
421 #ifndef HAVE_CFMAKERAW
423 void cfmakeraw(struct termios
*);
426 #ifndef HAVE_FREEZERO
428 void freezero(void *, size_t);
431 #ifndef HAVE_REALLOCARRAY
433 void *reallocarray(void *, size_t, size_t);
436 #ifndef HAVE_RECALLOCARRAY
437 /* recallocarray.c */
438 void *recallocarray(void *, size_t, size_t, size_t);
443 int systemd_activated(void);
444 int systemd_create_socket(int, char **);
445 int systemd_move_pid_to_new_cgroup(pid_t
, char **);
450 int utf8proc_wcwidth(wchar_t);
451 int utf8proc_mbtowc(wchar_t *, const char *, size_t);
452 int utf8proc_wctomb(char *, wchar_t);
457 #define main __weak main
461 extern int BSDopterr
;
462 extern int BSDoptind
;
463 extern int BSDoptopt
;
464 extern int BSDoptreset
;
465 extern char *BSDoptarg
;
466 int BSDgetopt(int, char *const *, const char *);
467 #define getopt(ac, av, o) BSDgetopt(ac, av, o)
468 #define opterr BSDopterr
469 #define optind BSDoptind
470 #define optopt BSDoptopt
471 #define optreset BSDoptreset
472 #define optarg BSDoptarg
474 #endif /* COMPAT_H */