notes@hcx1.UUCP (09/14/86)
Question: What should "putw" return? Our I/O library returns the error code for the "putw" operation, which is usually 0. In perusing BSD4.2 and ATT5.2.2 source, I see the same functionality. Yet the man pages seem to indicate that "putw" should return the "word" written. Is there a discrepancy between the code and the documentation? (The Perennial C test suite makes mention in a "bugs" section that the VAX 11/750 also returns "0" for putw in the particular test.) Dave Ray -- uucp: {ucf-cs|allegra}!novavax!hrshcx!hcx1!daver
guy@sun.uucp (Guy Harris) (09/17/86)
> Question: What should "putw" return? > > Our I/O library returns the error code for the "putw" operation, which is > usually 0. In perusing BSD4.2 and ATT5.2.2 source, I see the same > functionality. Which probably means it predates both of them, and worked that way in the V7-vintage standard I/O library. This would indicate it's probably supposed to. > Yet the man pages seem to indicate that "putw" should return the "word" > written. The trouble with returning the value written is that if you write the value -1, this can't be distinguished from EOF (at least on UNIX implementations, and others where EOF is -1), and unless you *know* that you won't be writing that value, you have to call "ferror" on that stream to detect errors. > Is there a discrepancy between the code and the documentation? Well, if there isn't, how do you explain the fact that the code and documentation disagree? More likely, you meant "There is a discrepancy between the code and the documentation; which is correct?" to which the answer is, most likely, "The code, in this case; the code has been that way for a long time, though several variations of UNIX, and 'fixing' it to agree with the documentation would cause other problems." > (The Perennial C test suite makes mention in a "bugs" section that the > VAX 11/750 also returns "0" for putw in the particular test.) Which is a very odd way of putting it; did the people who did that test suite to work differently on a VAX-11/780, for instance? -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com (or guy@sun.arpa)
gwyn@BRL.ARPA (VLD/VMB) (09/24/86)
There have been various versions of putw() on UNIX systems. Some returned the word written or EOF on failure, which was ambiguous. Somebody then decided that putw() should return 0 on success, EOF on failure. However, the implementation didn't follow the new spec. SVR3 has it that putw() should return ferror() or EOF on failure. I think this is the same as 0 or EOF. My feeling is that you should ignore the return value of putw() since there's no telling what it will be next week, and use ferror() to detect an error.