Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!ginosko!uunet!mcsun!sunic!dkuug!harald.ruc.dk!jba From: jba@harald.ruc.dk (Jan B. Andersen) Newsgroups: comp.unix.wizards Subject: Re: ENOTTY error when executing cp(1) Message-ID: <109@harald.UUCP> Date: 13 Sep 89 19:20:59 GMT References: <507@fdmetd.uucp> <2556@taux01.UUCP> <301@6sigma.UUCP> Organization: RUC - Roskilde University Center, Denmark Lines: 32 >In article <2556@taux01.UUCP> amos@taux01.UUCP (Amos Shapir) writes: >| To make sure >| its value is relevant, always clear errno before doing a system call. blm@6sigma.UUCP (Brian Matthews) writes: > Intro(2) (in my System V manuals) states: > "Errno is not cleared on successful calls, so it should be tested > only after an error has been indicated." >The second half of that sentence says to me that errno may be modified >even if the system call succeeds, so relying on errno staying zero is >a Bad Thing. But the first half of the sentence seems to talk about >clearing errno on success, so the second half might not say anything >about whether errno is modified on success. 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 ); } If you don't like if'ing the call do something like this: errno = 0; some_system_call(); if( errno ) { ... }