From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18612 invoked from network); 27 Jan 2023 23:16:49 -0000 Received: from lists.zx2c4.com (165.227.139.114) by inbox.vuxu.org with ESMTPUTF8; 27 Jan 2023 23:16:49 -0000 Received: by lists.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 7a48cf86; Fri, 27 Jan 2023 23:16:38 +0000 (UTC) Return-Path: Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [2607:f8b0:4864:20::632]) by lists.zx2c4.com (ZX2C4 Mail Server) with ESMTPS id 2fd965aa (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 27 Jan 2023 23:16:36 +0000 (UTC) Received: by mail-pl1-x632.google.com with SMTP id p24so6446832plw.11 for ; Fri, 27 Jan 2023 15:16:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mmayer-net.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/LNhvTy9kWgXcIRaWWiW+qs9v8iR3Ni+eyx8b5Ln5cY=; b=g6+cSN//CxFuhOCgec3fXlpnTMcZ84Gl+p1efN2crHGkjJpCHtntcdnp121me+qyv8 F+z9pxr3FT2Co1KrCP0LbvHMHgXi0gTRwmoP5CzGb/TIH4ODZVVVfuRr7KezZlY/BAx1 eQhpY773Iv6kanQpfRE2BR54TG4lcxM+fQrwb9xs9AB1DePg7tQ80v2kPEhtyDUE/hR1 T1kMR9egtF0hsqPBHpX2upwocAPf4b6p1WT6pciwax1E7G/1OpGkZ+u3QAvcFnmo430F WAfpehEhWgqlcHr/spDMouBSPpZUFbEtW1htvQzrsfZrc/jtP+BLLAWN3LEPdDEcitQ9 egZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/LNhvTy9kWgXcIRaWWiW+qs9v8iR3Ni+eyx8b5Ln5cY=; b=vdjhcqw6rIyNzeidr4c+c0/mPwtLck6Azy6idp3Rb2SPdJFXb9w/W28dphRLTxjFxe 68sgzbXXPXCGNj/sf/bjIF5yn08UWUNBZcHS11ji5Ul4bM/YbLv0sqs9/61MzU0IWboh 2RJivYYSnLgACXdnxEWKAm71ONQb0lxYygxGvGNHkSQjJXToIptYdejBsLx3GfH5fNot H7SbPA5aw0FD5Tjsekgw0g464JL+sTdDty+BBenQxuGSjWt4krhM8g3Luj7dChaQZtKB CytTNb2rUVbIBZWIqbS9zI42G0J687ahZ7XRh8+JoIghuwSV29xcKhfElThqORxW4Vqp v1qg== X-Gm-Message-State: AO0yUKUK9AHws8AQcJsHi5mB6VOz30OHGd8pSEZS/yRCVfMv+sSbV7L3 EIVeJm6sU3E2oZT6B9tiSvQaCFwThtWisEA9nKvg2g== X-Google-Smtp-Source: AK7set8hEj2SdI6E3NHvXvdiqx7dZp0wAT1qG+NIPHFG/3iySwzl8FiofbbNP0nxOepa/kx7J2Npfw== X-Received: by 2002:a17:903:1d1:b0:196:2c09:8726 with SMTP id e17-20020a17090301d100b001962c098726mr13067874plh.17.1674861394215; Fri, 27 Jan 2023 15:16:34 -0800 (PST) Return-Path: Received: from tethys.home.lan (S010600e0671fdc60.vs.shawcable.net. [70.71.78.140]) by smtp.gmail.com with ESMTPSA id g12-20020a170902fe0c00b00189f2fdc178sm3347412plj.177.2023.01.27.15.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 15:16:33 -0800 (PST) From: Markus Mayer To: CGIT List Cc: Markus Mayer Subject: [PATCH 1/1] global: provide memrchr implementation for macOS Date: Fri, 27 Jan 2023 15:15:43 -0800 Message-Id: <20230127231543.17977-2-code@mmayer.net> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230127231543.17977-1-code@mmayer.net> References: <20230127231543.17977-1-code@mmayer.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: cgit@lists.zx2c4.com X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: List for cgit developers and users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: cgit-bounces@lists.zx2c4.com Sender: "CGit" 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 modified in the following ways: - Removed unnecessary includes (config.h, sudo_compat.h). - Removed unnecessary include guard (HAVE_MEMRCHR). - Removed comment referencing an unrelated project. - Added comment mentioning URL to the original location of the file. Signed-off-by: Markus Mayer --- cgit.h | 4 ++++ cgit.mk | 9 +++++++++ memrchr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 memrchr.c diff --git a/cgit.h b/cgit.h index ddd2ccba0b88..19f810f22b61 100644 --- a/cgit.h +++ b/cgit.h @@ -397,4 +397,8 @@ extern char *expand_macros(const char *txt); 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 --git a/cgit.mk b/cgit.mk index 3fcc1ca31440..f85018c38b78 100644 --- a/cgit.mk +++ b/cgit.mk @@ -63,10 +63,19 @@ ifeq ($(uname_S),Linux) 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 diff --git a/memrchr.c b/memrchr.c new file mode 100644 index 000000000000..75c6dcde7432 --- /dev/null +++ b/memrchr.c @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: ISC + * + * Copyright (c) 2007, 2010-2014 + * Todd C. Miller + * + * 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. + */ + +/* + * Imported into CGIT from + * https://opensource.apple.com/source/sudo/sudo-87.80.2/sudo/lib/util/memrchr.c + */ + +#include + +/* + * 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; +} -- 2.39.0