[mod.computers.vax] read

jon@CSVAX.CALTECH.EDU (Jonathan P. Leech) (02/25/86)

	Is it a 'feature' of this release of DEC's C library that the
read() function will not read more than 1 RMS record at a time? I.e.
	fd = open("FOO", O_RDONLY, 0);
	bytes = read(fd, buffer, 1024);
invariably returns less than the requested 1024 bytes. If done on a .EXE
file, it returns 512 bytes (1 block); on a text file, it returns the number
of bytes in the first line, etc. Is there any way to defeat this behavior
with additional options to the open()? None of the RMS options mentioned
in table 18.2 in the C manual seem relevant, but I'm not familiar enough with
RMS to be sure.
	-- Jon Leech (jon@csvax.caltech.edu)
	__@/

EC0N@TE.CC.CMU.EDU (Eric R. Crane) (02/25/86)

		NOTE

	In general, the read function will not span record boundaries in
	a record file.  A seperate read must be done for each record.

That qoute comes from page 18-10 of Programming in VAX C, AA-L370B-TE.

- Erc
-------

Rudy.Nedved@A.CS.CMU.EDU (02/26/86)

Nothing int the semantics of Unix or C disallows returning less then the
buffer size. This has always been true for reading a line from a terminal
or getting incoming data from a network.

The only problem that I have come across with VMS C is that for some
reason a read() with a buffer size > 2**16 sometimes returns 0. I
hacked the code to always use a buffer less then 2**16 and the
problem went away....I was porting emacs which likes to do stats on
the file getting filesize X, allocs mem of size X and then does a
read of size X into the memory...it loops if the read is incomplete
but terminates with an error or eof if the read() returns <= 0.

-Rudy

sasaki@HARVARD.HARVARD.EDU (Marty Sasaki) (02/26/86)

It's a feature. You have to remember that VMS doesn't really know how
to deal with files that don't have a record type. In fact, files like
.exe's which seem to be without type, are fixed length records of 512
bytes.

You can do block read and writes regardless of the underlying format,
but you have to be careful to keep things straight since the files do
have record attributes.

Good luck.
			Marty Sasaki