aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

commit 3b143249b5fbbe6c6a4438fec4966a3a13edc639
parent f83eaf914ee40c3f19a16d4742045c9043d7e7b7
Author: xplshn <anto@xplshn.com.ar>
Date:   Fri, 27 Nov 2026 14:07:00 -0300

libmagic: magic_knows, whether a test gives a type

Diffstat:
Mshared/libmagic/magic.h | 5+++++
Mshared/libmagic/mgindex.c | 13+++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/shared/libmagic/magic.h b/shared/libmagic/magic.h @@ -100,6 +100,11 @@ int magic_prepare(struct Magic *m); */ int magic_fd_hint(struct Magic *m, int fd, const char *hint, char *desc, size_t dn, char *mime, size_t mn); /* + * whether a test can give mime: when one can and the file did not come + * out so, its name was wrong to say it. 0 without magic_prepare + */ +int magic_knows(const struct Magic *m, const char *mime); +/* * the charset file --mime prints for these bytes: "us-ascii", * "utf-8", "iso-8859-1" and so on, or "binary". the result is a * constant string diff --git a/shared/libmagic/mgindex.c b/shared/libmagic/mgindex.c @@ -279,3 +279,16 @@ mg_index_probe(struct MagicRun *r, unsigned char *buf, size_t have, size_t n, si } return k; } + +int +magic_knows(const struct Magic *m, const char *mime) +{ + size_t *pick, n; + long long reach; + + if (!m->ix || !mime) + return 0; + n = mg_index_pick(m->ix, mime, &pick, &reach); + free(pick); + return n > 0; +}