From 2704ef9f79a04e9f4f71e9cc7b5a1e33050482ae Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 5 Jan 2021 13:36:16 +1000
Subject: Fixes for haiku


diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e348996..e3b9bcf 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -26,7 +26,8 @@ target_link_libraries(KF5Pty PUBLIC Qt5::Core
                              PRIVATE
                                     ${UTIL_LIBRARY}
                                     ${kpty_OPTIONAL_LIBS}
-                                    KF5::I18n)
+                                    KF5::I18n
+                                    bsd)
 
 target_include_directories(KF5Pty PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..)
 
diff --git a/src/kpty.cpp b/src/kpty.cpp
index 55b057b..7e3ae34 100644
--- a/src/kpty.cpp
+++ b/src/kpty.cpp
@@ -69,7 +69,9 @@ public:
     int cmdFd;
 };
 #else
+# if HAVE_UTMP
 # include <utmp.h>
+# endif
 # if HAVE_UTMPX
 #  include <utmpx.h>
 # endif
@@ -318,6 +320,10 @@ grantedpt:
     fcntl(d->masterFd, F_SETFD, FD_CLOEXEC);
     fcntl(d->slaveFd, F_SETFD, FD_CLOEXEC);
 
+#ifdef __HAIKU__
+	setEcho(true);
+#endif
+
     return true;
 }
 
@@ -358,6 +364,10 @@ bool KPty::open(int fd)
         return false;
     }
 
+#ifdef __HAIKU__
+	setEcho(true);
+#endif
+
     return true;
 #endif
 }
diff --git a/src/kpty_p.h b/src/kpty_p.h
index 730ef98..9581a11 100644
--- a/src/kpty_p.h
+++ b/src/kpty_p.h
@@ -12,6 +12,19 @@
 
 #include <config-pty.h>
 
+#ifdef __HAIKU__
+#undef HAVE_OPENPTY
+#define HAVE_OPENPTY 1
+#undef HAVE_UTMP
+#define HAVE_UTMP 0
+#define ut_name ut_user
+#define ut_host ut_line
+#define _PATH_UTMPX ""
+#define _PATH_WTMPX ""
+#define utmpxname(a)
+#define updwtmpx(a, b)
+#endif
+
 #include <QByteArray>
 #include <QString>
 
-- 
2.28.0


From 2cefbabf9ff75582842d0bd6e208037cf7752c31 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 5 Jan 2021 13:45:26 +1000
Subject: Fixes for haiku2


diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e3b9bcf..a28557f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -81,7 +81,7 @@ endif()
 
 ########### next target ###############
 
-if (NOT HAVE_OPENPTY)
+if (NOT HAVE_OPENPTY AND NOT HAIKU)
    add_executable(kgrantpty kgrantpty.c)
    ecm_mark_nongui_executable(kgrantpty)
    install(TARGETS kgrantpty DESTINATION ${KDE_INSTALL_LIBEXECDIR_KF5})
-- 
2.28.0

