What's a good prototype for write(2)?
Richard A. O'Keefe
ok at quintus.uucp
Sun Oct 30 15:51:56 AEST 1988
In article <1988Oct28.170735.23991 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
>In article <902 at vsi.COM> friedl at vsi.COM (Stephen J. Friedl) writes:
>>What is a proper prototype for write(2)?
>> extern int write(int, const void *, unsigned); or
>> extern int write(int, const void *, int);
>
>The latter is correct. See any Unix manual.
Well, if you see the System V Interface Definition, you find in WRITE(BA_OS)
on page 148 of Volume 1
int write(filedes, buf, nbyte)
int filedes;
char *buf;
unsigned nbyte;
^^^^^^^^
Hardly surprising, as the argument is often (sizeof something), which is
unsigned. I read this as meaning that you can write up to USI_MAX-1 bytes
[see p29 to find out what USI_MAX is]. You have to be careful and test
int n = write(filedes, bug, nbyte);
unsigned u = n;
if (n == -1) { there was an error }
else { u bytes were written }
rather than
if (n < 0) { there was an error }
*OH* my broken programs...
Oddly enough, in a superb demonstration of consistency at its very best,
the SVID defines fread() and frwrite() in FWRITE(BA_OS) on p87 of the same
volume as taking >>int<< as the type of "size", and you pass in a
(sizeof something) which is in (INT_MAX,USI_MAX) fwrite() will write nothing.
More information about the Comp.std.c
mailing list