From 97c52e89aa8c04a05d16353f5f9ff05bcb807194 Mon Sep 17 00:00:00 2001
From: David CARLIER <devnexen@gmail.com>
Date: Sat, 29 Jan 2022 00:15:27 +0000
Subject: [PATCH] freebsd support update.

adding missing constants to fix warning at compile time.
providing tid fetching as well.
---
 lib/bcheck.c           | 6 +++++-
 tccpp.c                | 4 ++++
 tests/tests2/46_grep.c | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/bcheck.c b/lib/bcheck.c
index 0379b6e..8dabfba 100644
--- a/lib/bcheck.c
+++ b/lib/bcheck.c
@@ -228,7 +228,11 @@ typedef struct alloca_list_struct {
 #define BOUND_GET_TID    syscall (SYS_getthrid)
 #elif defined(__FreeBSD__) || defined(__NetBSD__)
 #define BOUND_TID_TYPE   pid_t
-#define BOUND_GET_TID    0
+#if defined(__FreeBSD__)
+#define BOUND_GET_TID    syscall (SYS_thr_self)
+#else
+#define BOUND_GET_TID    syscall (SYS_lwp_self)
+#endif
 #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__riscv)
 #define BOUND_TID_TYPE   pid_t
 #define BOUND_GET_TID    syscall (SYS_gettid)
diff --git a/tccpp.c b/tccpp.c
index 6b828c9..0a1b0fd 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -3743,6 +3743,10 @@ static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)
 #endif
     cstr_printf(cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE);
     cstr_printf(cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE);
+#ifdef TARGETOS_FreeBSD
+    cstr_printf(cs, "#define __SIZEOF_SIZE_T__ %d\n", LONG_SIZE);
+    cstr_printf(cs, "#define __SIZEOF_PTRDIFF_T__ %d\n", PTR_SIZE);
+#endif
     if (!is_asm) {
       putdef(cs, "__STDC__");
       cstr_printf(cs, "#define __STDC_VERSION__ %dL\n", s1->cversion);
diff --git a/tests/tests2/46_grep.c b/tests/tests2/46_grep.c
index acda793..530eaeb 100644
--- a/tests/tests2/46_grep.c
+++ b/tests/tests2/46_grep.c
@@ -14,6 +14,7 @@
  * included and reference made to  the  fact  that  reproduction
  * privileges were granted by DECUS.
  */
+#include <sys/cdefs.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>	// tolower()
-- 
2.34.1

