Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!ukc!edcastle!hwcs!zen!frank From: frank@zen.co.uk (Frank Wales) Newsgroups: comp.unix.wizards Subject: Re: ENOTTY error when executing cp(1) Message-ID: <1708@zen.co.uk> Date: 15 Sep 89 15:52:22 GMT References: <507@fdmetd.uucp> <2556@taux01.UUCP> <301@6sigma.UUCP> <109@harald.UUCP> Reply-To: frank@zen.co.uk (Frank Wales) Organization: Zengrange Limited, Leeds, England Lines: 37 In article <109@harald.UUCP> jba@harald.ruc.dk (Jan B. Andersen) writes: >As I see it, the "correct" way to check for errors is by coding something >like this: > > if( some_system_call() ) { > printf( "errno %d has occured in some_system_call()\n", errno ); > exit( errno ); > } Assuming some_system_call() returns true for failure, yes; this is not always the case, however. >If you don't like if'ing the call do something like this: > > errno = 0; > some_system_call(); > if( errno ) { > ... > } This isn't equivalent to the previous code fragment, and furthermore is not a valid use of errno; if you don't like the former style, then an alternative is: returnval=some_system_call(); if (returnval) { /* appropriate failure action... */ } It bears repeating that the purpose of errno is *not* to indicate system call failure, but to elaborate on the reason for such a failure. Examining it without due cause, such as some_system_call() returning a failure value, is wrong and dangerous, precisely because it sometimes seems to generate the right behaviour. -- 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