Comments from the original patch:
    macOS doesn't come with a memrchr() of its own, so let's provide an
    implementation it can use.

    memrchr.c was taken from Apple's own open source site.

    https://opensource.apple.com/source/sudo/sudo-87.80.2/sudo/lib/util/memrchr.c

    It was minimally modified, so it would work for cgit:
    - Removed #include "sudo_compat.h"
    - Renamed function from sudo_memrchr() to memrchr()

We can use this patch for now, until upstream has fixed it.

--- ../cgit-1.2.3.orig/cgit.h	2020-03-14 00:49:52.000000000 +0100
+++ ./cgit.h	2020-08-08 20:46:19.000000000 +0200
@@ -395,4 +395,8 @@

 extern char *get_mimetype_for_filename(const char *filename);

+#ifdef NEED_MEMRCHR
+extern void *memrchr(const void *s, int c, size_t n);
+#endif
+
 #endif /* CGIT_H */
diff -Naur ../cgit-1.2.3.orig/cgit.mk ./cgit.mk
--- ../cgit-1.2.3.orig/cgit.mk	2020-03-14 00:49:52.000000000 +0100
+++ ./cgit.mk	2020-08-08 20:49:02.000000000 +0200
@@ -63,10 +63,19 @@
 	HAVE_LINUX_SENDFILE = YesPlease
 endif

+ifeq ($(uname_S),Darwin)
+	IS_DARWIN = yes
+endif
+
 ifdef HAVE_LINUX_SENDFILE
 	CGIT_CFLAGS += -DHAVE_LINUX_SENDFILE
 endif

+ifdef IS_DARWIN
+	CGIT_CFLAGS += -DNEED_MEMRCHR
+	CGIT_OBJ_NAMES += memrchr.o
+endif
+
 CGIT_OBJ_NAMES += cgit.o
 CGIT_OBJ_NAMES += cache.o
 CGIT_OBJ_NAMES += cmd.o
--- /dev/null
+++ ./memrchr.c	2020-08-08 21:17:00.000000000 +0200
@@ -0,0 +1,49 @@
+/*
+ * SPDX-License-Identifier: ISC
+ *
+ * Copyright (c) 2007, 2010-2014
+ *	Todd C. Miller <Todd.Miller@sudo.ws>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * This is an open source non-commercial project. Dear PVS-Studio, please check it.
+ * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+ */
+
+#include <config.h>
+
+#ifndef HAVE_MEMRCHR
+
+#include <sys/types.h>
+
+/*
+ * Reverse memchr()
+ * Find the last occurrence of 'c' in the buffer 's' of size 'n'.
+ */
+void *
+memrchr(const void *s, int c, size_t n)
+{
+	const unsigned char *cp;
+
+	if (n != 0) {
+		cp = (unsigned char *)s + n;
+		do {
+			if (*(--cp) == (unsigned char)c)
+				return (void *)cp;
+		} while (--n != 0);
+	}
+	return (void *)0;
+}
+#endif /* HAVE_MEMRCHR */
