From 794d3a552090aca0aab92834635afc6cb4329568 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Sat, 15 May 2021 20:14:27 +0300
Subject: [PATCH 03/29] TERMUX ifdefs in guicast

---
 cinelerra-5.1/guicast/Makefile     |  7 +++++++
 cinelerra-5.1/guicast/bthread.h    | 31 ++++++++++++++++++++++++++++++
 cinelerra-5.1/guicast/filesystem.C |  3 ++-
 cinelerra-5.1/guicast/thread.C     |  5 +++++
 cinelerra-5.1/guicast/thread.h     |  4 +++-
 cinelerra-5.1/guicast/vframe.C     | 10 +++++-----
 cinelerra-5.1/guicast/vframe.h     |  3 ++-
 7 files changed, 55 insertions(+), 8 deletions(-)
 create mode 100644 cinelerra-5.1/guicast/bthread.h

diff --git a/cinelerra-5.1/guicast/Makefile b/cinelerra-5.1/guicast/Makefile
index cf189dea..fc086f92 100644
--- a/cinelerra-5.1/guicast/Makefile
+++ b/cinelerra-5.1/guicast/Makefile
@@ -12,6 +12,11 @@ ifeq ($(OBJDIR), amd64)
 BOOTSTRAPFLAGS := -DBOOTSTRAP="\"objcopy -B i386 -I binary -O elf64-x86-64\""
 endif
 
+ifeq ($(OBJDIR), armv8l)
+BOOTSTRAPFLAGS := -DBOOTSTRAP="\"objcopy -B arm -I binary -O elf32-littlearm\""
+endif
+
+
 $(shell mkdir -p $(OBJDIR) )
 
 OBJS = \
@@ -83,6 +88,7 @@ OBJS = \
 	$(OBJDIR)/vicon.o \
 	$(OBJDIR)/workarounds.o
 
+
 OUTPUT = $(OBJDIR)/libguicast.a
 
 UTILS = $(OBJDIR)/bootstrap $(OBJDIR)/pngtoh $(OBJDIR)/pngtoraw
@@ -90,6 +96,7 @@ BCXFER = xfer/$(OBJDIR)/xfer.stamp
 
 CFLAGS += $(static_incs)
 
+
 $(shell echo $(CFLAGS) > $(OBJDIR)/c_flags)
 $(shell echo $(OBJS) > $(OBJDIR)/objs)
 
diff --git a/cinelerra-5.1/guicast/bthread.h b/cinelerra-5.1/guicast/bthread.h
new file mode 100644
index 00000000..57a0c492
--- /dev/null
+++ b/cinelerra-5.1/guicast/bthread.h
@@ -0,0 +1,31 @@
+/* BThread main header
+   Copyright (C) 2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+# define PTHREAD_CANCEL_ENABLE    	 0x00000010
+# define PTHREAD_CANCEL_DISABLE   	 0x00000000
+
+# define PTHREAD_CANCEL_ASYNCHRONOUS 0x00000020
+# define PTHREAD_CANCEL_DEFERRED     0x00000000
+
+#define PTHREAD_CANCELED ((void *) -1)
+
+int pthread_setcancelstate (int , int *);
+int pthread_setcanceltype (int , int *);
+void pthread_testcancel (void);
+int pthread_cancel (pthread_t t);
diff --git a/cinelerra-5.1/guicast/filesystem.C b/cinelerra-5.1/guicast/filesystem.C
index 6017f6ea..b1ace6fd 100644
--- a/cinelerra-5.1/guicast/filesystem.C
+++ b/cinelerra-5.1/guicast/filesystem.C
@@ -536,7 +536,7 @@ int FileSystem::parse_tildas(char *new_dir)
 				new_user[j] = new_dir[i];
 			}
 			new_user[j] = 0;
-
+#if !defined(__TERMUX__)
 			setpwent();
 			while( (pw = getpwent()) != 0 )
 			{
@@ -550,6 +550,7 @@ int FileSystem::parse_tildas(char *new_dir)
       			}
 			}
 			endpwent();
+#endif
 			return 0;
 		}
 	}
diff --git a/cinelerra-5.1/guicast/thread.C b/cinelerra-5.1/guicast/thread.C
index 50b52a47..9908a628 100644
--- a/cinelerra-5.1/guicast/thread.C
+++ b/cinelerra-5.1/guicast/thread.C
@@ -28,6 +28,9 @@
 #include <string.h>
 #include <typeinfo>
 #include "thread.h"
+#if defined(__TERMUX__)
+#include "bthread.h"
+#endif
 
 
 Thread::Thread(int synchronous, int realtime, int autodelete)
@@ -102,8 +105,10 @@ void Thread::start()
 			perror("Thread::start pthread_attr_setschedparam");
 	}
 	else {
+#if !defined(__TERMUX__)
 		if(pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED) < 0)
 			perror("Thread::start pthread_attr_setinheritsched");
+#endif
 	}
 
 // autodelete may delete this immediately after create
diff --git a/cinelerra-5.1/guicast/thread.h b/cinelerra-5.1/guicast/thread.h
index 79f3e713..e701a8f4 100644
--- a/cinelerra-5.1/guicast/thread.h
+++ b/cinelerra-5.1/guicast/thread.h
@@ -29,13 +29,15 @@
 #ifndef NO_TID
 #include <sys/syscall.h>
 
+#if !defined(__TERMUX__)
 // glibc >= 2.30 provides gettid() in unistd
 #if !defined(__GLIBC_PREREQ) || !__GLIBC_PREREQ(2, 30)
 static inline int gettid() { return syscall(SYS_gettid, 0, 0, 0); }
-#endif
 #else
 static inline long gettid() { return (long)pthread_self(); }
 #endif
+#endif // TERMUX
+#endif //no_tid
 
 // The thread does not autodelete by default.
 // If autodelete is 1 the thread autodeletes.
diff --git a/cinelerra-5.1/guicast/vframe.C b/cinelerra-5.1/guicast/vframe.C
index af0e52a8..44d7f97e 100644
--- a/cinelerra-5.1/guicast/vframe.C
+++ b/cinelerra-5.1/guicast/vframe.C
@@ -334,7 +334,7 @@ if( memory_type != VFrame::SHARED )
 			shmid = -1;
 			break;
 
-		case VFrame::SHMGET:
+		case VFrame::SHM_GET:
 			if(data)
 				shmdt(data);
 			data = 0;
@@ -510,7 +510,7 @@ int VFrame::allocate_data(unsigned char *data, int shmid,
 		this->v_offset = v_offset;
 	}
 	else if( shmid >= 0 ) {
-		memory_type = VFrame::SHMGET;
+		memory_type = VFrame::SHM_GET;
 		this->data = (unsigned char*)shmat(shmid, NULL, 0);
 		if( this->data == (unsigned char*)-1 ) {
 			printf("VFrame::allocate_data %d could not attach"
@@ -593,7 +593,7 @@ void VFrame::set_memory(unsigned char *data,
 	else
 	if(shmid >= 0)
 	{
-		memory_type = VFrame::SHMGET;
+		memory_type = VFrame::SHM_GET;
 		this->data = (unsigned char*)shmat(shmid, NULL, 0);
 		this->shmid = shmid;
 	}
@@ -635,7 +635,7 @@ void VFrame::set_compressed_memory(unsigned char *data,
 	else
 	if(shmid >= 0)
 	{
-		memory_type = VFrame::SHMGET;
+		memory_type = VFrame::SHM_GET;
 		this->data = (unsigned char*)shmat(shmid, NULL, 0);
 		this->shmid = shmid;
 	}
@@ -713,7 +713,7 @@ UNBUFFER(data);
 			else
 				free(data);
 		}
-		else if( memory_type == VFrame::SHMGET ) {
+		else if( memory_type == VFrame::SHM_GET ) {
 			if( data ) shmdt(data);
 		}
 
diff --git a/cinelerra-5.1/guicast/vframe.h b/cinelerra-5.1/guicast/vframe.h
index 589fce1c..55590bda 100644
--- a/cinelerra-5.1/guicast/vframe.h
+++ b/cinelerra-5.1/guicast/vframe.h
@@ -31,6 +31,7 @@
 #include "bccmodels.h"
 #include "vframe.inc"
 
+
 // Maximum number of prev or next effects to be pushed onto the stacks.
 #define MAX_STACK_ELEMENTS 255
 #define SHM_MIN_SIZE 2048
@@ -417,7 +418,7 @@ private:
 	{
 		PRIVATE,
 		SHARED,
-		SHMGET
+		SHM_GET
 	};
 
 // Data pointer is pointing to someone else's buffer.
-- 
2.31.1

