sscanf always generates error condition

Jonathan I. Kamens jik at athena.mit.edu
Fri May 3 19:55:41 AEST 1991


In article <1991May2.134354.9719 at dg-rtp.dg.com>, hunt at dg-rtp.rtp.dg.com (Greg Hunt) writes:
|> GV> I was aware that the it wouldn't set errno=0, but setting it to a
|> GV> non-zero value on normal termination still bothers me.
|> 
|> It would bother me, too.  It might be a bug in the ISC sscanf library
|> call (albeit a fairly harmless one since the function works and does
|> return the proper value).

  It is *not* a bug.  The specification of the system call interface is that
if a system call succeeds, errno is irrelevant, and its value is undefined. 
The value is only defined if the system call fails.

  There are quite a few system calls in the kernel that set errno to a value,
then try the operation which would cause that error value if it failed, and
then return immediately it it fails, signalling an error.  They're allowed to
do that.

  You cannot count on the value of errno being zero if a function succeeds. 
That's the way the system call interface is designed, and, in all likelihood,
that design is ingrained in too many different systems for it to be changed in
the foreseeable future.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.programmer mailing list