What's a good prototype for write(2)?

Rahul Dhesi dhesi at bsu-cs.UUCP
Thu Oct 27 07:50:31 AEST 1988


In article <902 at vsi.COM> friedl at vsi.COM (Stephen J. Friedl) wants
to choose between
>	extern int write(int, const void *, unsigned);
and
>	extern int write(int, const void *, int);

If you assume the ability to write more bytes than will fit in an int,
then neither is correct, since write() returns the number of bytes
actually written.  A correct form is, with the exception that
I'm not sure if "const" is needed, is:

     extern unsigned int write (int fd, void *, unsigned int count);

The return value from write is then the number of bytes actually
written, or defined to be ERR_UNSIGNED in case of an error.  Naturally,
you would have to make sure that write() does indeed return
ERR_UNSIGNED and change the manuals accordingly.

Also:

#define   ERR_UNSIGNED    ((unsigned int) -1)
-- 
Rahul Dhesi         UUCP:  <backbones>!{iuvax,pur-ee}!bsu-cs!dhesi



More information about the Comp.std.c mailing list