Checking return values (was: Trojan Horses, NFS, etc.)

Ronald S H Khoo ronald at robobar.co.uk
Thu Oct 25 17:58:56 AEST 1990


[ wizard readers: skip now.  followups redirected. ]

scs at adam.mit.edu (Steve Summit) writes:

>			default:
>				fprintf(stderr, "%s: can't open %s: ",
>							progname, name);
>				perror("");

usenet: can't open scs at adam.mit.edu: not a tty.

(Steve, I'm shocked!  *you* of all people :-)

For those of you still puzzled: perror() must be called *immediately* after the
error returns, or the internal error state may be modified by calls
to system calls in the intervening situation.  It's annoying, but

	perror(name);
	fprintf(stderr, "%s: error opening %s (see error message above)\n",
		progname, name);

is more correct.

-- 
ronald at robobar.co.uk +44 81 991 1142 (O) +44 71 229 7741 (H)



More information about the Comp.unix.programmer mailing list