ENOTTY error when executing cp(1)
Frank Wales
frank at zen.co.uk
Sat Sep 16 01:52:22 AEST 1989
In article <109 at harald.UUCP> jba at 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 at zen.co.uk<->mcvax!zen.co.uk!frank]
Zengrange Ltd., Greenfield Rd., Leeds, ENGLAND, LS9 8DB. (+44) 532 489048 x217
More information about the Comp.unix.wizards
mailing list