VMS Specific question about binary reads using fgetc

Bradford R. Daniels daniels at hanoi.enet.dec.com
Fri Jun 15 07:50:10 AEST 1990


In article <2081 at mindlink.UUCP>, a204 at mindlink.UUCP (Alexander
Stockdale) writes:
> Regarding reads from RMS files, I've played with this at various times.
> It always works better if the the file characteristic is Stream-LF (the
> UNIX format).  There are utilities which will convert files to this
format for
> you (check some of the DECUS tapes).  If you don't want to convert, you'll
> probably have to modify the code so it knows about the implicit
carriage return
> information in the file.  This can be a real hassle, depending on what
the code
> is supposed to do.  For example, if
> you're trying to strip CR/LF, no problem.  If, on the other hand,
you're trying
> to convert them to something else, this can be a real hassle.

The reason stream-LF works so well is that we access stream-lf files
in block mode by default (i.e., we have RMS do direct QIOs to the
file.)  Since we pay no attention to the record format of the file
in block mode, we can provide a much higher degree of Unix emulation,
particularly as regards file positioning.  Unfortunately, though,
block mode I/O is much slower than record mode I/O because it can-
not use such beneficial features as multibuffering, read-ahead, and
write-behind.

The important thing to remember about the VAX C/VMS RTL is that it
always tries to make the data it reads in look like a stream, even
if there is record structuring information in the file.  That means 
that things like record boundaries and carriage control have an effect
on the data you receive.  If you accept the default behavior, you will
usually get the right behavior.  If you randomly throw RMS options at
the open statement, specify binary data when you don't mean it, or
give a file carriage control attributes it shouldn't have, however,
you won't get the right behavior.

I'm not saying the carriage control attributes on a file are always
control, but in general, these are good rules of thumb:

	1.  If the file contains text, it should either be streamlf
	    or some form of variable record length file with an
	    appropriate carriage control attribute.

	2.  If the file contains binary data, it should either be
	    streamlf format (possibly with carriage return carriage
	    control,) or some other format with no carriage control.
	    The latter is preferable, since a legal stream-lf file
	    is supposed to end with a newline, and real binary files
	    rarely do.  Of course, if you never access the file in
	    record mode, it doesn't really matter.

	3.  Don't use "b" mode in fopen unless the file really is
	    just binary data.  You will usually lose any line
	    formatting information there may be in the file (e.g.
	    newlines if the file uses carriage return carriage
	    control).

I had some others in mind when I started, but I can't remember them
right now...  I'm sure a future question will bring them to mind,
though...

- Brad

-----------------------------------------------------------------
Brad Daniels			|  Digital Equipment Corp. almost
DEC Software Devo		|  definitely wouldn't approve of
"VAX C RTL Whipping Boy"	|  anything I say here...



More information about the Comp.lang.c mailing list