summaryrefslogtreecommitdiff
path: root/src/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/file.c')
-rw-r--r--src/file.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/file.c b/src/file.c
index 87dd1bb60f4c..5b60b95f4240 100644
--- a/src/file.c
+++ b/src/file.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.175 2018/03/02 16:11:37 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.181 2019/03/28 20:54:03 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -128,6 +128,7 @@ private const struct {
{ "encoding", MAGIC_NO_CHECK_ENCODING },
{ "soft", MAGIC_NO_CHECK_SOFT },
{ "tar", MAGIC_NO_CHECK_TAR },
+ { "json", MAGIC_NO_CHECK_JSON },
{ "text", MAGIC_NO_CHECK_TEXT }, /* synonym for ascii */
{ "tokens", MAGIC_NO_CHECK_TOKENS }, /* OBSOLETE: ignored for backwards compatibility */
};
@@ -136,14 +137,15 @@ private struct {
const char *name;
int tag;
size_t value;
+ int set;
} pm[] = {
- { "indir", MAGIC_PARAM_INDIR_MAX, 0 },
- { "name", MAGIC_PARAM_NAME_MAX, 0 },
- { "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0 },
- { "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0 },
- { "elf_notes", MAGIC_PARAM_ELF_NOTES_MAX, 0 },
- { "regex", MAGIC_PARAM_REGEX_MAX, 0 },
- { "bytes", MAGIC_PARAM_BYTES_MAX, 0 },
+ { "indir", MAGIC_PARAM_INDIR_MAX, 0, 0 },
+ { "name", MAGIC_PARAM_NAME_MAX, 0, 0 },
+ { "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0, 0 },
+ { "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0, 0 },
+ { "elf_notes", MAGIC_PARAM_ELF_NOTES_MAX, 0, 0 },
+ { "regex", MAGIC_PARAM_REGEX_MAX, 0, 0 },
+ { "bytes", MAGIC_PARAM_BYTES_MAX, 0, 0 },
};
private int posixly;
@@ -184,9 +186,7 @@ main(int argc, char *argv[])
char *progname;
/* makes islower etc work for other langs */
-#ifdef HAVE_SETLOCALE
(void)setlocale(LC_CTYPE, "");
-#endif
#ifdef __EMX__
/* sh-like wildcard expansion! Shouldn't hurt at least ... */
@@ -242,11 +242,11 @@ main(int argc, char *argv[])
flags |= MAGIC_ERROR;
break;
case 'e':
- for (i = 0; i < sizeof(nv) / sizeof(nv[0]); i++)
+ for (i = 0; i < __arraycount(nv); i++)
if (strcmp(nv[i].name, optarg) == 0)
break;
- if (i == sizeof(nv) / sizeof(nv[0]))
+ if (i == __arraycount(nv))
errflg++;
else
flags |= nv[i].value;
@@ -398,7 +398,8 @@ main(int argc, char *argv[])
}
else {
size_t j, wid, nw;
- for (wid = 0, j = (size_t)optind; j < (size_t)argc; j++) {
+ for (wid = 0, j = CAST(size_t, optind); j < CAST(size_t, argc);
+ j++) {
nw = file_mbswidth(argv[j]);
if (nw > wid)
wid = nw;
@@ -426,7 +427,7 @@ applyparam(magic_t magic)
size_t i;
for (i = 0; i < __arraycount(pm); i++) {
- if (pm[i].value == 0)
+ if (!pm[i].set)
continue;
if (magic_setparam(magic, pm[i].tag, &pm[i].value) == -1)
file_err(EXIT_FAILURE, "Can't set %s", pm[i].name);
@@ -446,6 +447,7 @@ setparam(const char *p)
if (strncmp(p, pm[i].name, s - p) != 0)
continue;
pm[i].value = atoi(s + 1);
+ pm[i].set = 1;
return;
}
badparm:
@@ -534,9 +536,8 @@ process(struct magic_set *ms, const char *inname, int wid)
(void)putc('\0', stdout);
if (nulsep < 2) {
(void)printf("%s", separator);
- (void)printf("%*s ",
- (int) (nopad ? 0 : (wid - file_mbswidth(inname))),
- "");
+ (void)printf("%*s ", CAST(int, nopad ? 0
+ : (wid - file_mbswidth(inname))), "");
}
}
@@ -563,8 +564,8 @@ file_mbswidth(const char *s)
while (n > 0) {
bytesconsumed = mbrtowc(&nextchar, s, n, &state);
- if (bytesconsumed == (size_t)(-1) ||
- bytesconsumed == (size_t)(-2)) {
+ if (bytesconsumed == CAST(size_t, -1) ||
+ bytesconsumed == CAST(size_t, -2)) {
/* Something went wrong, return something reasonable */
return old_n;
}
@@ -623,13 +624,13 @@ docprint(const char *opts, int def)
for (sp = p - 1; sp > opts && *sp == ' '; sp--)
continue;
- fprintf(stdout, "%.*s", (int)(p - opts), opts);
+ fprintf(stdout, "%.*s", CAST(int, p - opts), opts);
comma = 0;
for (i = 0; i < __arraycount(nv); i++) {
fprintf(stdout, "%s%s", comma++ ? ", " : "", nv[i].name);
- if (i && i % 5 == 0) {
- fprintf(stdout, ",\n%*s", (int)(p - sp - 1), "");
+ if (i && i % 5 == 0 && i != __arraycount(nv) - 1) {
+ fprintf(stdout, ",\n%*s", CAST(int, p - sp - 1), "");
comma = 0;
}
}
@@ -653,7 +654,7 @@ help(void)
#include "file_opts.h"
#undef OPT
#undef OPT_LONGONLY
- fprintf(stdout, "\nReport bugs to http://bugs.gw.com/\n");
+ fprintf(stdout, "\nReport bugs to https://bugs.astron.com/\n");
exit(EXIT_SUCCESS);
}