Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!amdcad!sun!pitstop!sundc!seismo!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: Detecting type of file in a program Message-ID: <949@auspex.UUCP> Date: 4 Feb 89 21:41:41 GMT References: <192@henry.ece.utexas.edu> <9587@smoke.BRL.MIL> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 19 >Anything you do will be pretty much what "file" does, >namely, inspect yay many bytes of the file to see if there is a >known "magic number" header present or if there are non-diplayable >byte values present. Note, of course, that: 1) the set of known magic numbers is not "constant" in any sense, so you have to pick a set and hope it's sufficient (or let "file" do it, if your system supports an S5-style "file", and make sure the "/etc/magic" file is up-to-date and complete); 2) you should use "isprint" to determine what is a "non-displayable byte value"; do NOT assume that any byte with its 8th bit set is necessarily non-printable (actually, if you have files with character codes longer than 1 byte, e.g. files containing Kanji, it gets even more complicated).