[mod.computers.vax] File attributes - binary?

BRENT@uwovax.UWO.CDN (Brent Sterner) (01/20/87)

   I have a user who wants to write a simple editor.  He would like
to reject editing of a "binary" file.  How does he determine whether
or not an existing file is "binary"?  Is there any file attribute he
can check, and how should he go about doing it?  I believ "C" is his
language of choice.  Thanks as always, Brent.
--
Brent Sterner
Lord Protector,  d i g i t a l  Systems
Computing & Communications Services
Natural Sciences Building
The University of Western Ontario
London, Ontario, Canada  N6A 5B7
Telephone (519)661-2151 x6036
Network     <BRENT@uwovax.UWO.CDN>  ! VAX 8600
            <A105@UWOCC1.BITNET>    ! IBM 4341

carl@CITHEX.CALTECH.EDU.UUCP (01/21/87)

The routine "stat" in the C run time library fills a structure also called
"stat" that contains, among other things, the elements:

stat.st_mode:		the file "mode", part of which lets you tell if the
			file's a directory, a terminal, etc.
stat.st_fab_rfm:	the file's record format (e.g. fixed variable, or
		        stream records, and indexed, relative, or sequential
			file organization.)
stat.st_fab_rat:	record attributes (what sort of carriage control
			is associated with the records of this file, and can
		       	records cross block boundaries?

Now, "text" files tend to:
	1) Not be directories;
	2) Have a record format of either variable length or some sort of
	   stream records;
	3) Belong to files organized sequentially;
	4) Have PRINT, FORTRAN, or IMPLIED (CARRIAGE-RETURN) carriage control
	   attributes, and the blocks are generally allowed to cross block
	   boundaries.
Checking these fields in the stat structure will come about as close as
you can come to deciding whether you're dealing with a "text" file or a 
binary file without resorting to something like:
	1) Checking a few of the leading records of the file to discover
	   whether they conform to the formats of, say executable, object,
	   or library files; or
	2) Running the thing through a dictionary so see if it has may
	   recognizable words in it.