List for cgit developers and users
 help / color / mirror / Atom feed
* Re: [PATCH] global: provide memrchr implementation for macOS
  2020-08-08 22:28 [PATCH] global: provide memrchr implementation for macOS Markus Mayer
@ 2020-08-08 22:33 ` Markus Mayer
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Mayer @ 2020-08-08 22:33 UTC (permalink / raw)
  To: CGIT Mailing List

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 <code@mmayer.net> 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 <code@mmayer.net>
> ---
>
> 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 <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 */
> --
> 2.26.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] global: provide memrchr implementation for macOS
@ 2020-08-08 22:28 Markus Mayer
  2020-08-08 22:33 ` Markus Mayer
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Mayer @ 2020-08-08 22:28 UTC (permalink / raw)
  To: CGIT Mailing List; +Cc: Markus Mayer

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 <code@mmayer.net>
---

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 <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 */
-- 
2.26.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] global: provide memrchr implementation for macOS
@ 2020-08-08 18:12 Markus Mayer
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Mayer @ 2020-08-08 18:12 UTC (permalink / raw)
  To: CGit list

[-- Attachment #1: Type: text/plain, Size: 301 bytes --]

Hi,

This is my third attempt at getting this patch to show up on the
mailing list. Since I am not having any luck with "git send-email" and
since this issue has just come up for others, I am sticking the patch
into an attachment. Sorry about that, but I don't know what else to
do.

Regards,
-Markus

[-- Attachment #2: 0001-global-provide-memrchr-implementation-for-macOS.patch --]
[-- Type: application/octet-stream, Size: 3406 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-08 22:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-08 22:28 [PATCH] global: provide memrchr implementation for macOS Markus Mayer
2020-08-08 22:33 ` Markus Mayer
  -- strict thread matches above, loose matches on Subject: below --
2020-08-08 18:12 Markus Mayer

List for cgit developers and users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/cgit

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 cgit cgit/ http://inbox.vuxu.org/cgit \
		cgit@lists.zx2c4.com
	public-inbox-index cgit

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.cgit


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git