From 733682191dbc9d9e230bc1dd60de4530640c6486 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zolt=C3=A1n=20Mizsei?= <zmizsei@extrowerk.com>
Date: Tue, 22 Aug 2017 18:43:38 +0200
Subject: Haiku patches


diff --git a/include/c.h b/include/c.h
index 02e9e59..902b5e6 100644
--- a/include/c.h
+++ b/include/c.h
@@ -33,6 +33,10 @@
 # define NAME_MAX PATH_MAX
 #endif
 
+#ifndef _SC_HOST_NAME_MAX
+#define _SC_HOST_NAME_MAX 72
+#endif
+
 /*
  * __GNUC_PREREQ is deprecated in favour of __has_attribute() and
  * __has_feature(). The __has macros are supported by clang and gcc>=5.
diff --git a/include/ttyutils.h b/include/ttyutils.h
index f164a58..2ac1c88 100644
--- a/include/ttyutils.h
+++ b/include/ttyutils.h
@@ -91,15 +91,23 @@ extern int get_terminal_name(const char **path, const char **name,
 static inline void reset_virtual_console(struct termios *tp, int flags)
 {
 	/* Use defaults of <sys/ttydefaults.h> for base settings */
+#ifdef TTYDEF_IFLAG
 	tp->c_iflag |= TTYDEF_IFLAG;
+#endif
+#ifdef TTYDEF_OFLAG
 	tp->c_oflag |= TTYDEF_OFLAG;
+#endif
+#ifdef TTYDEF_LFLAG
 	tp->c_lflag |= TTYDEF_LFLAG;
+#endif
 
 	if ((flags & UL_TTY_KEEPCFLAGS) == 0) {
 #ifdef CBAUD
 		tp->c_lflag &= ~CBAUD;
 #endif
+#ifdef TTYDEF_CFLAG
 		tp->c_cflag |= (B38400 | TTYDEF_CFLAG);
+#endif
 	}
 
 	/* Sane setting, allow eight bit characters, no carriage return delay
@@ -151,7 +159,11 @@ static inline void reset_virtual_console(struct termios *tp, int flags)
 # define TABDLY 0
 #endif
 
+#ifdef IMAXBEL
 	tp->c_iflag |=  (BRKINT | ICRNL | IMAXBEL);
+#else
+	tp->c_iflag |=  (BRKINT | ICRNL);
+#endif
 	tp->c_iflag &= ~(IGNBRK | INLCR | IGNCR | IXOFF | IUCLC | IXANY | ISTRIP);
 	tp->c_oflag |=  (OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0);
 	tp->c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | \
@@ -181,24 +193,48 @@ static inline void reset_virtual_console(struct termios *tp, int flags)
 	 */
 	tp->c_cc[VTIME]    = 0;
 	tp->c_cc[VMIN]     = 1;
+#ifdef CINTR
 	tp->c_cc[VINTR]    = CINTR;
+#endif
+#ifdef CQUIT
 	tp->c_cc[VQUIT]    = CQUIT;
+#endif
+#ifdef CERASE
 	tp->c_cc[VERASE]   = CERASE; /* ASCII DEL (0177) */
+#endif
+#ifdef CKILL
 	tp->c_cc[VKILL]    = CKILL;
+#endif
+#ifdef CEOF
 	tp->c_cc[VEOF]     = CEOF;
+#endif
 #ifdef VSWTC
 	tp->c_cc[VSWTC]    = _POSIX_VDISABLE;
 #elif defined(VSWTCH)
 	tp->c_cc[VSWTCH]   = _POSIX_VDISABLE;
 #endif
+#ifdef CSTART
 	tp->c_cc[VSTART]   = CSTART;
+#endif
+#ifdef CSTOP
 	tp->c_cc[VSTOP]    = CSTOP;
+#endif
+#ifdef CSUSP
 	tp->c_cc[VSUSP]    = CSUSP;
+#endif
 	tp->c_cc[VEOL]     = _POSIX_VDISABLE;
+#ifdef VREPRINT
 	tp->c_cc[VREPRINT] = CREPRINT;
+#endif
+#ifdef VDISCARD
 	tp->c_cc[VDISCARD] = CDISCARD;
+#endif
+#ifdef VWERASE
 	tp->c_cc[VWERASE]  = CWERASE;
+#endif
+#ifdef CLNEXT
 	tp->c_cc[VLNEXT]   = CLNEXT;
+#endif
 	tp->c_cc[VEOL2]    = _POSIX_VDISABLE;
 }
 
diff --git a/lib/randutils.c b/lib/randutils.c
index de42795..9e07457 100644
--- a/lib/randutils.c
+++ b/lib/randutils.c
@@ -13,7 +13,9 @@
 #include <string.h>
 #include <sys/time.h>
 
+#ifndef __HAIKU__
 #include <sys/syscall.h>
+#endif
 
 #include "c.h"
 #include "randutils.h"
-- 
2.23.0


From b16f1be478a7cb39cc0fd09ad3dc80e551f344f2 Mon Sep 17 00:00:00 2001
From: fbrosson <fbrosson@localhost>
Date: Tue, 6 Nov 2018 13:55:22 +0000
Subject: define {makedev,major,minor} macros


diff --git a/include/c.h b/include/c.h
index 902b5e6..f5d4cbd 100644
--- a/include/c.h
+++ b/include/c.h
@@ -23,6 +23,10 @@
 
 #ifdef HAVE_SYS_SYSMACROS_H
 # include <sys/sysmacros.h>     /* for major, minor */
+#else
+#define makedev(ma, mi) ((dev_t)(((((unsigned int)(ma)) << 8) & 0xff00) | (mi)))
+#define major(devnum) (((unsigned int)((devnum) & 0xff00) >> 8))
+#define minor(devnum) (unsigned int)((devnum) & 0xffff00ff)
 #endif
 
 #ifndef LOGIN_NAME_MAX
-- 
2.23.0


From f8485aeff00b3c3c1ce1ebfb6fc7dc6a852b6864 Mon Sep 17 00:00:00 2001
From: fbrosson <fbrosson@localhost>
Date: Tue, 6 Nov 2018 14:07:17 +0000
Subject: Don't define macros if they require others which are undefined.


diff --git a/include/ttyutils.h b/include/ttyutils.h
index 2ac1c88..e5bb761 100644
--- a/include/ttyutils.h
+++ b/include/ttyutils.h
@@ -43,22 +43,32 @@
 
 /* Default termios->iflag */
 #ifndef TTYDEF_IFLAG
+# if defined(BRKINT) && defined(ICRNL) && defined(IMAXBEL) && defined(IXON) && \
+     defined(IXANY)
 # define TTYDEF_IFLAG	(BRKINT | ICRNL | IMAXBEL | IXON | IXANY)
+# endif
 #endif
 
 /* Default termios->oflag */
 #ifndef TTYDEF_OFLAG
+# if defined(OPOST) && defined(ONLCR)
 # define TTYDEF_OFLAG	(OPOST | ONLCR /*| OXTABS*/)
+# endif
 #endif
 
 /* Default termios->lflag */
 #ifndef TTYDEF_LFLAG
+# if defined(ECHO) && defined(ICANON) && defined(ISIG) && defined(IEXTEN) && \
+     defined(IXANY) && defined(ECHOE) && defined(ECHOKE) && defined(ECHOCTL)
 # define TTYDEF_LFLAG	(ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
+# endif
 #endif
 
 /* Default termios->cflag */
 #ifndef TTYDEF_CFLAG
+# if defined(CREAD) && defined(CS8) && defined(HUPCL)
 # define TTYDEF_CFLAG	(CREAD | CS8 | HUPCL)
+# endif
 #endif
 
 /* Storage for things detected while the login name was read. */
-- 
2.23.0


From a811da01d6200b3a6c9f5615a206dfaa4f1d4faa Mon Sep 17 00:00:00 2001
From: fbrosson <fbrosson@localhost>
Date: Thu, 8 Nov 2018 07:27:38 +0000
Subject: Skip tests which fail to build.


diff --git a/tests/helpers/Makemodule.am b/tests/helpers/Makemodule.am
index ab0b3ce..393af5e 100644
--- a/tests/helpers/Makemodule.am
+++ b/tests/helpers/Makemodule.am
@@ -21,8 +21,8 @@ check_PROGRAMS += test_sigreceive
 test_sigreceive_SOURCES = tests/helpers/test_sigreceive.c
 test_sigreceive_LDADD = $(LDADD) libcommon.la
 
-check_PROGRAMS += test_tiocsti
-test_tiocsti_SOURCES = tests/helpers/test_tiocsti.c
+# check_PROGRAMS += test_tiocsti
+# test_tiocsti_SOURCES = tests/helpers/test_tiocsti.c
 
 check_PROGRAMS += test_uuid_namespace
 test_uuid_namespace_SOURCES = tests/helpers/test_uuid_namespace.c \
-- 
2.23.0


From f772bbf679db9ae00e291b0d87cccde0763bafe9 Mon Sep 17 00:00:00 2001
From: fbrosson <fbrosson@localhost>
Date: Thu, 8 Nov 2018 07:29:11 +0000
Subject: include posix/syslog.h instead of sys/syslog.h


diff --git a/login-utils/logindefs.c b/login-utils/logindefs.c
index 2b505d2..d6218d3 100644
--- a/login-utils/logindefs.c
+++ b/login-utils/logindefs.c
@@ -26,7 +26,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifndef __HAIKU__
 #include <sys/syslog.h>
+#else
+#include <posix/syslog.h>
+#endif
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <pwd.h>
-- 
2.23.0

