Path: utzoo!attcan!uunet!cs.utexas.edu!yale!mintaka!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: fgets Keywords: tc, tc++ Message-ID: <18635@haddock.ima.isc.com> Date: 25 Oct 90 03:53:47 GMT References: <52039@unix.cis.pitt.edu> <576@inews.intel.com> Reply-To: karl@ima.isc.com (Karl Heuer) Distribution: na Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 23 In article <576@inews.intel.com> bhoughto@cmdnfs.intel.com (Blair P. Houghton) writes: >In article <52039@unix.cis.pitt.edu> ydist@unix.cis.pitt.edu (Yijun Ding) writes: >>fputs("", fp) return 0 in TC 2.0 >> return (-1) in TC++ >> >>Which is correct ? > >Under ANSI, the return value on error from fputs() is an EOF, the >return value if no error is "nonnegative". [Perhaps some nonstandard >system is using 0 for failure.] I don't think so. It looks to me as though both implementations agree that -1 means failure, but it's questionable whether a zero-length write is a failure or a trivial success. (There are all sorts of dark corners when dealing with zero-sized objects; the answer can be "operation fails", "operation succeeds", or "behavior undefined" depending on the details.) If the Standard isn't clear on this (sorry, I can't look it up just now), one can always send X3J11 a request for interpretation. The pragmatic solution is to rewrite the code so it doesn't matter: if (*s != '\0' && fputs(s, fp) == EOF) panic(); Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint