summaryrefslogtreecommitdiffstats
path: root/contrib/file/softmagic.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/file/softmagic.c')
-rw-r--r--contrib/file/softmagic.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/contrib/file/softmagic.c b/contrib/file/softmagic.c
index daf9ccd..88f5214 100644
--- a/contrib/file/softmagic.c
+++ b/contrib/file/softmagic.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.133 2008/11/07 22:50:37 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.135 2009/03/27 22:42:49 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -256,11 +256,14 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
* make sure that we have a separator first.
*/
if (*m->desc) {
- printed_something = 1;
if ((e = handle_annotation(ms, m)) != 0)
return e;
- if (print_sep(ms, firstline) == -1)
- return -1;
+ if (!printed_something) {
+ printed_something = 1;
+ if (print_sep(ms, firstline)
+ == -1)
+ return -1;
+ }
}
/*
* This continuation matched. Print
@@ -338,14 +341,13 @@ strndup(const char *str, size_t n)
size_t len;
char *copy;
- len = strlen(str);
- if (len > n)
- len = n;
- if (!(copy = malloc(len + 1)))
- return (NULL);
- (void) memcpy(copy, str, len + 1);
+ for (len = 0; len < n && str[len]; len++)
+ continue;
+ if ((copy = malloc(len + 1)) == NULL)
+ return NULL;
+ (void)memcpy(copy, str, len);
copy[len] = '\0';
- return (copy);
+ return copy;
}
#endif /* HAVE_STRNDUP */
OpenPOWER on IntegriCloud