[comp.lang.c] A question about ANSI C file handling

ath@my.cvab.SE (Anders Thulin) (03/15/88)

I understand that the ANSI draft standard of C requires binary files
to be opened in binary mode, using for instance:
 
  f = fopen(file, "rb");

Does anybody know if there is a way (in ANSI C) to determine whether
a file is binary or not?  Does fopen fail if a binary file isn't
opened as binary?

Thanks,

Anders Thulin, ContextVision AB, Teknikringen 1, S-583 30 Linkoping, SWEDEN
INET: [@uunet.uu.net:]ath@cvab.se	UUCP: {uunet,mcvax}!enea!cvab!ath
PHONE: +46 13 20 31 00	FAX: +46 13 21 29 75	TELEX: 50020 contex s

gwyn@brl-smoke.ARPA (Doug Gwyn ) (03/19/88)

In article <12385@brl-adm.ARPA> ath@my.cvab.SE (Anders Thulin) writes:
>Does anybody know if there is a way (in ANSI C) to determine whether
>a file is binary or not?

There can't be, because some systems do not maintain anything in the
file system that says whether a file is to be considered binary or not.
For example, UNIX.

>Does fopen fail if a binary file isn't opened as binary?

It is allowed to, but not required to (for the same reason as above).

In other words, it is up to the application to use the right mode.