Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!sumax!polari!6sigma!blm From: blm@6sigma.UUCP (Brian Matthews) Newsgroups: comp.unix.wizards Subject: Re: ENOTTY error when executing cp(1) Message-ID: <302@6sigma.UUCP> Date: 15 Sep 89 18:55:10 GMT References: <507@fdmetd.uucp> <2556@taux01.UUCP> <301@6sigma.UUCP> <109@harald.UUCP> Reply-To: blm@6sigma.UUCP (Brian Matthews) Organization: Six Sigma CASE, Inc. Lines: 31 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 ); | } Two problems with this: 1. You should use perror so the user gets a reason for the failure, not just a number. 2. errno isn't preserved across many stdio calls, so the exit will not exit with the errno generated by some_system_call. |If you don't like if'ing the call do something like this: | errno = 0; | some_system_call(); | if( errno ) { | ... | } My question was basically, is that guaranteed to work. I suspected not, but couldn't find anything to prove it. Doug Gwyn has since posted that you can't do this - some_system_call may set errno to any arbitrary value, yet still succeed. -- Brian L. Matthews blm@6sigma.UUCP Six Sigma CASE, Inc. +1 206 854 6578 PO Box 40316, Bellevue, WA 98004