[ian@darwinsys.com: thoughts on libmagic]
Ian Darwin
ian at darwinsys.com
Fri May 16 22:20:16 EDT 2003
Two issues:
1) What would you think about splitting "src" into two directories,
one for libmagic and the other for file? It turns out easier for
support on BSD systems to have each in its own directory, so you
can use <bsd.lib.mk> and <bsd.prog.mk>
2) I'm thinking out loud here, but there ought to be a more general
structure to the interaction with libmagic, something like
magic_open_file(const char *filename);
which would either set state or, preferably, return an opaque
struct, and in either case could be followed up with macros/functions.
My general model here is stat(2). Things we have wanted to know in an
application include the following:
boolean is_binary() / is_text()
Lots of programs want to know this, e.g., lpr to know
if it's safe to print a file.
char *get_type()
to get the file type (what file normally prints)
char *get_mime_type()
to get the mime type.
A web server for example might want to print a directory listing
and would use get_type() in the printed listing but would use
get_mime_type() to actually send the file. The notion as now that
this must be set at magic_open time, or twiddled using flags,
strikes me as improvable. What do the rest of you think?
Ian
More information about the File
mailing list