summary refs log tree commit diff
path: root/compat.h
diff options
context:
space:
mode:
Diffstat (limited to 'compat.h')
-rw-r--r--compat.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/compat.h b/compat.h
new file mode 100644
index 0000000..ad0b45d
--- /dev/null
+++ b/compat.h
@@ -0,0 +1,115 @@
+#ifndef COMPAT_H
+#define COMPAT_H
+
+#include <sys/types.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#ifndef __OpenBSD__
+#ifndef HOST_NAME_MAX
+#ifdef _POSIX_HOST_NAME_MAX
+#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
+#else
+#define HOST_NAME_MAX 255
+#endif
+#endif
+
+#ifndef LOGIN_NAME_MAX
+#ifdef _POSIX_LOGIN_NAME_MAX
+#define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX
+#else
+#define LOGIN_NAME_MAX 256
+#endif
+#endif
+
+#ifndef HAVE_STRTONUM
+#define HAVE_STRTONUM
+long long strtonum(const char *numstr, long long minval, long long maxval,
+    const char **errstrp);
+#endif
+
+#ifndef HAVE_STRLCPY
+#define HAVE_STRLCPY
+size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif
+
+#ifndef HAVE_ERR
+#define HAVE_ERR
+void err(int eval, const char *fmt, ...);
+void errx(int eval, const char *fmt, ...);
+void warn(const char *fmt, ...);
+void warnx(const char *fmt, ...);
+#endif
+
+#ifndef HAVE_TIMESPECADD
+#define HAVE_TIMESPECADD
+#define timespecadd(tsp, usp, vsp) \
+	do { \
+		(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
+		(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
+		if ((vsp)->tv_nsec >= 1000000000L) { \
+			(vsp)->tv_sec++; \
+			(vsp)->tv_nsec -= 1000000000L; \
+		} \
+	} while (0)
+#define timespecsub(tsp, usp, vsp) \
+	do { \
+		(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
+		(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
+		if ((vsp)->tv_nsec < 0) { \
+			(vsp)->tv_sec--; \
+			(vsp)->tv_nsec += 1000000000L; \
+		} \
+	} while (0)
+#endif
+
+#ifndef HAVE_PLEDGE
+#define HAVE_PLEDGE
+static inline int pledge(const char *promises, const char *execpromises) {
+	(void)promises;
+	(void)execpromises;
+	return 0;
+}
+#endif
+
+#if !defined(__OpenBSD__)
+#include <poll.h>
+#include <time.h>
+#include <signal.h>
+int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts,
+    const sigset_t *sigmask);
+#endif
+
+#if defined(__APPLE__) && !defined(HAVE_STRNVIS)
+#define HAVE_STRNVIS
+#ifndef COMPAT_C_IMPL
+int strnvis_openbsd(char *dst, const char *src, size_t dlen, int flags);
+#define strnvis strnvis_openbsd
+#endif
+#endif
+
+#ifndef HAVE_B64_NTOP
+#define HAVE_B64_NTOP
+#ifndef u_char
+#define u_char unsigned char
+#endif
+int b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize);
+#endif
+#endif
+
+#if defined(__linux__) && !defined(HAVE_FUNOPEN)
+#define HAVE_FUNOPEN
+#define _GNU_SOURCE
+#include <stdio.h>
+FILE *funopen(const void *cookie, 
+    int (*readfn)(void *, char *, int),
+    int (*writefn)(void *, const char *, int),
+    fpos_t (*seekfn)(void *, fpos_t, int),
+    int (*closefn)(void *));
+#endif
+
+#endif
\ No newline at end of file