Questions about read() and write()

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Wed Dec 26 16:06:15 AEST 1984


> strange things about read().
> 
> For starters, the function returns an int.  One passes an unsigned number
> of bytes which specifies the maximum number of characters which should be
> returned.  The return value is a non-negative integer indicating the actual
> number of bytes read, or -1.

That's right; this bogosity is required for backward compatibility.
I advise not telling read() or write() to handle more bytes than can
be expressed in an int.

> Nextly, what happens to the current file position if a read() or write() is
> interrupted?

Filesystem I/O is not interrupted by signals.

> What happens if, under 4.2, an alarm call causes the read() or write() to
> be restarted for me (is there a good reason why this was changed in 4.2)?

I/O to/from a slow device (e.g. terminal) is automatically restarted by
4.2BSD.  This was somebody's "better idea" that breaks existing code.
You can avoid the automatic system call restart by some kludgery first
described by Donn Seeley and posted by me several months ago.



More information about the Comp.unix.wizards mailing list