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=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 350 invoked from network); 8 Aug 2020 22:33:44 -0000 Received: from krantz.zx2c4.com (192.95.5.69) by inbox.vuxu.org with ESMTPUTF8; 8 Aug 2020 22:33:44 -0000 Received: by krantz.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 8ffb2673; Sat, 8 Aug 2020 22:08:45 +0000 (UTC) Return-Path: Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [2a00:1450:4864:20::541]) by krantz.zx2c4.com (ZX2C4 Mail Server) with ESMTPS id 541f9016 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Sat, 8 Aug 2020 22:08:42 +0000 (UTC) Received: by mail-ed1-x541.google.com with SMTP id q4so3778008edv.13 for ; Sat, 08 Aug 2020 15:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mmayer-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=VQDCNdKGEtH4z8bNgEpGkoFYQLrhrYPXXrRvoHRS8cw=; b=TYWFncyNW/UttI68Aq9KglHYXMKV/kvE/n37Dgj8wF0GkfRfCpRAwy7qLmxVflIJ+J W2jrmlKyMWS921Xxgn/QlvJQSg83sHkt1etQiEeWwl9BGBpcxCYwXmSS5Grr/xW2QByb w2xR9X+mIEvNs77vBn/W6LBcFEORQEADMB6l9yqbuq/Lud4NzsT+aHmsRrhu0TkoDMnk 6bbGZcJiMCveh7BvxgSHFZ93XtG9GQ9fKO8Ym7a5K1rSY6qPRhIa/V5CpXcA2CQPQG3k 4zfSorCGlDmqvkSHrb0EsDkpiM8TUSgRLHdgKQAoePtA17zx49Ak3ULFdEjnoWuN+HLx ZM5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=VQDCNdKGEtH4z8bNgEpGkoFYQLrhrYPXXrRvoHRS8cw=; b=fzeJMyXBD74n5a3LoVZkuVi3cb3fEJyvmqIGQq4fnE1ccWlR8brIqiFHYbF4xpiYlT JLHfF5e5It5l7Ae7iltbrXWpCc4lDceAdmNZ8Uy9dDEnMySY8dkNzBpw/08+MJRB0yZI lUE8NtfexiLAzqFhICXcQIX9Fsqp4dJWQOneuOcPj59sOtx0e7aeI0ImbODuXhJ2GAq7 ncXa6tfMmXQz0dewnSUgxxvmfHIdltRoj9KkavFb7Hq7u4I/BmxPkjBN2MHq0kVN6j8r 3JhRVzvM2v/ad94cDZzpaPIdKbIT7EfHDncTwPjIvogfZOpSfOmr05KA5Zi7w8/CofhB mo/w== X-Gm-Message-State: AOAM531rsm/in17T/yNP62QSzFC8HAJxzXjDDk1sBBe3ZDmUWBZaqzTb rpwJFrLS6Cee8+MRkLluUgxF0WCsQhXFrWEeKqpr/nngoR9W95fm X-Google-Smtp-Source: ABdhPJyofCif/aOtxqvh7K7wAHoP3fsW3W4jL53gxkQxAF/gltDRtoZypHVSixYbdtZJzItbTcuzrlGIz3GyWc99lh8= X-Received: by 2002:a50:ef0a:: with SMTP id m10mr15070913eds.226.1596926016644; Sat, 08 Aug 2020 15:33:36 -0700 (PDT) MIME-Version: 1.0 References: <20200808222808.46263-1-code@mmayer.net> In-Reply-To: <20200808222808.46263-1-code@mmayer.net> From: Markus Mayer Date: Sat, 8 Aug 2020 15:33:26 -0700 Message-ID: Subject: Re: [PATCH] global: provide memrchr implementation for macOS To: CGIT Mailing List Content-Type: text/plain; charset="UTF-8" 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" Looks like the 4th time's the charm (since the attachment was stripped by the list software). E-mail setup issues have been resolved. Sorry for the hassle. Regards, -Markus On Sat, 8 Aug 2020 at 15:28, Markus Mayer wrote: > > 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() > > Signed-off-by: Markus Mayer > --- > > I sent this a few days ago already, but it looks like it didn't make it > to the mailig list. Let's give it another shot. > > cgit.h | 4 ++++ > cgit.mk | 9 +++++++++ > memrchr.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 62 insertions(+) > create mode 100644 memrchr.c > > diff --git a/cgit.h b/cgit.h > index 7ec46b4..1b2f712 100644 > --- a/cgit.h > +++ b/cgit.h > @@ -395,4 +395,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 3fcc1ca..f85018c 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 0000000..46ec17f > --- /dev/null > +++ b/memrchr.c > @@ -0,0 +1,49 @@ > +/* > + * 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. > + */ > + > +/* > + * 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 > + > +#ifndef HAVE_MEMRCHR > + > +#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; > +} > +#endif /* HAVE_MEMRCHR */ > -- > 2.26.0 >