Would it be possible to use the BSD/MIT-licensed file utility? ftp://ftp.astron.com/pub/file/file-4.17.tar.gz It's a tool to guess what the file type is by taking a look at the beginning of the file, especially the first few bytes (called the (file) magic number). I think almost all variants of Unix have it, and it even includes a magic number to MIME type converter. If nothing else, the file src/ascmagic.c contains nice code to detect if the file is text or not and even guesses its encoding. -- Ville Koskinen