openbsd-ports/devel/libmagic/patches/patch-src_softmagic_c
rui 482c0795ea - update to 5.00, based on initial diff from Benoit Lecocq.
- fix build on Vax while here

ok naddy@
2009-04-04 18:28:14 +00:00

40 lines
923 B
Plaintext

$OpenBSD: patch-src_softmagic_c,v 1.4 2009/04/04 18:28:15 rui Exp $
--- src/softmagic.c.orig Fri Nov 7 22:50:37 2008
+++ src/softmagic.c Sat Mar 28 13:22:45 2009
@@ -331,21 +331,26 @@ check_fmt(struct magic_set *ms, struct magic *m)
#ifndef HAVE_STRNDUP
char * strndup(const char *, size_t);
+size_t strnlen (const char *, size_t);
+size_t
+strnlen (const char *string, size_t maxlen)
+{
+ const char *end = memchr (string, '\0', maxlen);
+ return end ? (size_t) (end - string) : maxlen;
+}
+
char *
strndup(const char *str, size_t n)
{
- size_t len;
- char *copy;
+ size_t len = strnlen (str, n);
+ char *copy = malloc (len + 1);
- len = strlen(str);
- if (len > n)
- len = n;
- if (!(copy = malloc(len + 1)))
- return (NULL);
- (void) memcpy(copy, str, len + 1);
+ if (copy == NULL)
+ return NULL;
+
copy[len] = '\0';
- return (copy);
+ return memcpy (copy, str, len);
}
#endif /* HAVE_STRNDUP */