detecting file type by magic number


Subject: detecting file type by magic number
From: Kevin Vajk (kvajk@ricochet.net)
Date: Thu Jan 20 2000 - 01:34:07 CST


Based mostly on the Linux "file" command (/usr/share/magic), I've
written a few C functions which, given a filename, return 1 if
they think the file is of the type they recognize, else 0.

The functions I've written are:
    int file_is_abiword_1(char *filename);
    int file_is_gzipped_abiword_1(char *filename); /* needs zlib */
    int file_is_rtf(char *filename);
    int file_is_html(char *filename);
    int file_is_microsoft_word(char *filename);

Any interest? Is this primitive approach of value?

By the way, moving the "<abiword..." line to the start of
the .abw files would make it a lot easier to add an entry to
/usr/share/magic so that "file foo.abw" could be made to
work as expected on Linux/UNIX. I'd highly recommend doing
this, as I think "file" is used by various file managers
to determine what application to launch to open the file
with.

- Kevin Vajk
  <kvajk@ricochet.net>



This archive was generated by hypermail 2b25 : Thu Jan 20 2000 - 01:37:44 CST