aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjylefort <jylefort@FreeBSD.org>2006-11-08 00:07:35 +0800
committerjylefort <jylefort@FreeBSD.org>2006-11-08 00:07:35 +0800
commit83d83e19ed9e3e4cc11718a7dd21a25011ce9158 (patch)
treea404586a290d28702023c46e876439e35370407f
parent025f04bd066c62d70acffd91bf6abb86dff4d751 (diff)
downloadfreebsd-ports-gnome-83d83e19ed9e3e4cc11718a7dd21a25011ce9158.tar.gz
freebsd-ports-gnome-83d83e19ed9e3e4cc11718a7dd21a25011ce9158.tar.zst
freebsd-ports-gnome-83d83e19ed9e3e4cc11718a7dd21a25011ce9158.zip
Provide a memmem() if the system lacks it.
Reported by: Frank W. Josellis <frank@dynamical-systems.org>
-rw-r--r--archivers/unmakeself/Makefile10
-rw-r--r--archivers/unmakeself/files/unmakeself.c35
2 files changed, 44 insertions, 1 deletions
diff --git a/archivers/unmakeself/Makefile b/archivers/unmakeself/Makefile
index 704799081d5e..e7d6b837c2e8 100644
--- a/archivers/unmakeself/Makefile
+++ b/archivers/unmakeself/Makefile
@@ -27,8 +27,16 @@ CPPFLAGS+= -I${LOCALBASE}/include
LDFLAGS+= -L${LOCALBASE}/lib
.endif
+do-configure:
+ @${RM} -f ${WRKSRC}/config.h
+ @if ${GREP} -q memmem /usr/include/string.h; then \
+ ${ECHO_CMD} "#define HAS_MEMMEM" > ${WRKSRC}/config.h; \
+ else \
+ ${ECHO_CMD} "#undef HAS_MEMMEM" > ${WRKSRC}/config.h; \
+ fi
+
do-build:
- ${CC} ${CFLAGS} ${CPPFLAGS} -o ${WRKSRC}/unmakeself \
+ ${CC} ${CFLAGS} ${CPPFLAGS} -I${WRKSRC} -o ${WRKSRC}/unmakeself \
${FILESDIR}/unmakeself.c ${LDFLAGS}
do-install:
diff --git a/archivers/unmakeself/files/unmakeself.c b/archivers/unmakeself/files/unmakeself.c
index d4b9542e110a..bc275d19b6e2 100644
--- a/archivers/unmakeself/files/unmakeself.c
+++ b/archivers/unmakeself/files/unmakeself.c
@@ -42,6 +42,7 @@
#include <unistd.h>
#include <getopt.h>
#include <archive.h>
+#include "config.h"
#define N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
@@ -50,6 +51,40 @@ static char *filename;
static struct archive *archive;
static int extract_flags = ARCHIVE_EXTRACT_TIME; /* bsdtar default */
+#ifndef HAS_MEMMEM
+/* taken from lib/libc/string/memmem.c */
+static void *
+memmem(l, l_len, s, s_len)
+ const void *l; size_t l_len;
+ const void *s; size_t s_len;
+{
+ register char *cur, *last;
+ const char *cl = (const char *)l;
+ const char *cs = (const char *)s;
+
+ /* we need something to compare */
+ if (l_len == 0 || s_len == 0)
+ return NULL;
+
+ /* "s" must be smaller or equal to "l" */
+ if (l_len < s_len)
+ return NULL;
+
+ /* special case where s_len == 1 */
+ if (s_len == 1)
+ return memchr(l, (int)*cs, l_len);
+
+ /* the last position where its possible to find "s" in "l" */
+ last = (char *)cl + l_len - s_len;
+
+ for (cur = (char *)cl; cur <= last; cur++)
+ if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
+ return cur;
+
+ return NULL;
+}
+#endif /* HAS_MEMMEM */
+
static void
unmakeself_print_help (void)
{