[Scottish] type of files

Michael Cameron scottish at mailman.lug.org.uk
Wed Aug 28 16:38:01 2002


>
>file(1) works by looking for magic numbers in the head of a file.  For
>example, if it notes that the first 4 bytes of a file are '\177ELF', it
>will decide that it's an ELF-format executable.
>
file can work by looking to the filesystem, magic then language, whichever
works first is used.  The filesystem tests are based on stat() which I
imagine uses sys/types.h, this detects empty files, sockets, pipes etc..
Magic is described above and finally language tests look at the file content
to see if it is text.  If it is then various different tests are used to try
and determine what type of text (ASCII, UTF-8) etc..

Couldn't say how I'd do it in c (probably because I wouldn't).  Hope this
helps.

MC