🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5424

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

#5424
From: Richard A. O'Keefe
Date: Sun, 30 Oct 1988 05:51
30 lines
1748 bytes
In article <1988Oct28.170735.23991@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes:
>In article <902@vsi.COM> friedl@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.
Technical Details
Message-ID: <603@quintus.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!mcdchg!chinet!att!pacbell!lll-tis!lll-winken!arisia!quintus!ok
References: <902@vsi.COM> <1988Oct28.170735.23991@utzoo.uucp>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!mcdchg!chinet!att!pacbell!lll-tis!lll-winken!arisia!quintus!ok
From: ok@quintus.uucp (Richard A. O'Keefe)
Newsgroups: comp.std.c
Subject: Re: What's a good prototype for write(2)?
Message-ID: <603@quintus.UUCP>
Date: 30 Oct 88 05:51:56 GMT
References: <902@vsi.COM> <1988Oct28.170735.23991@utzoo.uucp>
Sender: news@quintus.UUCP
Reply-To: ok@quintus.UUCP (Richard A. O'Keefe)
Organization: Quintus Computer Systems, Inc.
Lines: 29