C
Chris Torek
There could be systems that keep text and binary files completely
separate, such that no operations are allowed on the wrong type.
I don't know of any, though.
VMS does something arguably more useful than that. In VMS, files
have a great deal of structure, which is normally managed by RMS
(the "record management system" -- code that, as Ken Thompson wrote
so long ago, "fills a much-needed gap" ). If you have a file
with (say) variable-length records, and open it as a fixed-length
record file, RMS will pad and (I presume) truncate records as
required to fit the data into the Procrustean bed. Similarly, if
you open a variable-length record file as text, RMS (or the C
runtime library -- pre-VMS-5.0 and Stream-LF files, I imagine it
was done outside RMS proper) can break up the records with
artificially-inserted newlines.
In any case, if one has ever actually used these operating systems
that fail to provide the much-needed gap -- i.e., the ones that
have a plethora of forcibly-imposed file formats -- one should
begin to understand the strong constraints put on the C programmer
by the C standards.