openbsd-ports/devel/libmagic/patches/patch-src_softmagic_c
rui 647b139ecf update libmagic to 4.21
ok mbalmer@, ajacoutot@
2007-06-08 17:49:40 +00:00

40 lines
923 B
Plaintext

$OpenBSD: patch-src_softmagic_c,v 1.2 2007/06/08 17:49:40 rui Exp $
--- src/softmagic.c.orig Tue May 8 15:44:18 2007
+++ src/softmagic.c Thu Jun 7 23:54:20 2007
@@ -288,21 +288,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 */