Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!apple!sun-barr!decwrl!ucbvax!hplabs!hpfcdc!stroyan From: stroyan@hpfcdc.HP.COM (Mike Stroyan) Newsgroups: comp.sys.hp Subject: Re: Strange behaviour on HP9000/825 Message-ID: <5570246@hpfcdc.HP.COM> Date: 26 Jul 89 20:00:48 GMT References: <227@innovus.UUCP> Organization: HP Ft. Collins, Co. Lines: 20 > File opens, errno=0, fp=1073742056 > File read, errno=25, fp=1073742056, buffer=#include > File read2, errno=0, fp=1073742056, buffer=#include > > Anybody care to comment about why this is happening? The fopen is checking isatty() to see if it should buffer the stream output. The isatty call is using a failed ioctl() call to see that the file is not a tty. The failed ioctl() call is setting errno to ENOTTY. Your program is checking the value of errno without first checking ferror() or the return value from fgets(). You can't depend on the value of errno being to be 0 when an error has not occured. You must first determine that an error occured, then use errno to find out more about the error. The errno value is not always defined to reflect the state of libraries such as stdio. While some library calls will refer the user to errno for more information, it is really intended to return information about kernel calls rather than arbitrary library calls. Mike Stroyan, stroyan@hpfcla.hp.com