summaryrefslogtreecommitdiffstats
path: root/usr.bin/file/magic-common.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2015-08-11 21:42:16 +0000
committernicm <nicm@openbsd.org>2015-08-11 21:42:16 +0000
commit5c6c4bceed3f1599b98671fc7d3923c4047fdebe (patch)
tree8d2b8db4fbaeb498d1f2463ba8af34cbe127153e /usr.bin/file/magic-common.c
parentDon't inline long functions as this tends to increase object size (diff)
downloadwireguard-openbsd-5c6c4bceed3f1599b98671fc7d3923c4047fdebe.tar.xz
wireguard-openbsd-5c6c4bceed3f1599b98671fc7d3923c4047fdebe.zip
Add another function for printing warnings before the magic_line is
created so all warnings go through the same fprintf.
Diffstat (limited to 'usr.bin/file/magic-common.c')
-rw-r--r--usr.bin/file/magic-common.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/usr.bin/file/magic-common.c b/usr.bin/file/magic-common.c
index e84d113b962..c00d54f77a7 100644
--- a/usr.bin/file/magic-common.c
+++ b/usr.bin/file/magic-common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: magic-common.c,v 1.1 2015/04/24 16:24:11 nicm Exp $ */
+/* $OpenBSD: magic-common.c,v 1.2 2015/08/11 21:42:16 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
@@ -63,21 +63,35 @@ magic_strtoll(const char *s, int64_t *i)
}
void
-magic_warn(struct magic_line *ml, const char *fmt, ...)
+magic_vwarnm(struct magic *m, u_int line, const char *fmt, va_list ap)
{
- va_list ap;
char *msg;
- if (!ml->root->warnings)
+ if (!m->warnings)
return;
- va_start(ap, fmt);
- if (vasprintf(&msg, fmt, ap) == -1) {
- va_end(ap);
+ if (vasprintf(&msg, fmt, ap) == -1)
return;
- }
+ fprintf(stderr, "%s:%u: %s\n", m->path, line, msg);
+ free(msg);
+}
+
+void
+magic_warnm(struct magic *m, u_int line, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ magic_vwarnm (m, line, fmt, ap);
va_end(ap);
+}
- fprintf(stderr, "%s:%u: %s\n", ml->root->path, ml->line, msg);
- free(msg);
+void
+magic_warn(struct magic_line *ml, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ magic_vwarnm (ml->root, ml->line, fmt, ap);
+ va_end(ap);
}