Path: utzoo!attcan!uunet!mcsun!ukc!edcastle!hwcs!zen!frank From: frank@zen.co.uk (Frank Wales) Newsgroups: comp.sys.hp Subject: Re: Extraneous error code under 3.1? Message-ID: <2046@zen.co.uk> Date: 23 Nov 89 14:26:19 GMT References: Reply-To: frank@zen.co.uk (Frank Wales) Organization: Zengrange Limited, Leeds, England Lines: 29 In article jthomas@nmsu.edu (James Thomas) writes: >System: HP 9000/840 under HP-UX 3.1 [Exactly our set-up here; the problem you describe is a generic Unix problem, however, and not unique to HP-UX.] >When we run the following code in either form (with the fgets or fscanf), >the first fgets/fscanf call returns an error code of 25 . If that is >cleared, following calls do not touch errno . Would someone else please >try this and report back your results? >[example program deleted] The behaviour you have noted is what I would expect, and is not a problem. Unless a system call or library function actually *returns* a failure code as documented for the call or function in question, the value of errno is undefined, and can be anything. Many library calls cause errors to happen as part of their normal operation, but none are obliged to reset errno to zero if they eventually succeed. For example, fgets/fscanf probably perform an ioctl on their input as part of stdio set-up operations during their first invocation, and in the case in question, this would fail (errno 25==ENOTTY). In short, errno should *only* be used to discover more information about an already-reported error; it should not be used to detect the error in the first place. -- Frank Wales, Systems Manager, [frank@zen.co.uk<->mcvax!zen.co.uk!frank] Zengrange Ltd., Greenfield Rd., Leeds, ENGLAND, LS9 8DB. (+44) 532 489048 x217