ENOTTY error when executing cp(1)

Brian Matthews blm at 6sigma.UUCP
Sat Sep 16 04:55:10 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 );
|  }

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 at 6sigma.UUCP
Six Sigma CASE, Inc.			+1 206 854 6578
PO Box 40316, Bellevue, WA  98004



More information about the Comp.unix.wizards mailing list