From owner-freebsd-current Tue Jun 16 17:33:40 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA29765 for freebsd-current-outgoing; Tue, 16 Jun 1998 17:33:40 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from spinner.netplex.com.au (spinner.netplex.com.au [202.12.86.3]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA29757 for ; Tue, 16 Jun 1998 17:33:33 -0700 (PDT) (envelope-from peter@netplex.com.au) Received: from spinner.netplex.com.au (localhost [127.0.0.1]) by spinner.netplex.com.au (8.8.8/8.8.8/Spinner) with ESMTP id IAA06067; Wed, 17 Jun 1998 08:32:57 +0800 (WST) (envelope-from peter@spinner.netplex.com.au) Message-Id: <199806170032.IAA06067@spinner.netplex.com.au> X-Mailer: exmh version 2.0.2 2/24/98 To: Terry Lambert cc: current@FreeBSD.ORG Subject: Re: Bogus errno twiddling by lstat... In-reply-to: Your message of "Tue, 16 Jun 1998 23:55:32 GMT." <199806162355.QAA06852@usr02.primenet.com> Date: Wed, 17 Jun 1998 08:32:56 +0800 From: Peter Wemm Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Terry Lambert wrote: > Try the following program: > > #include > #include > #include > > > main() > { > struct stat sb; > > errno = 0; > printf( "lstat(fred) = %d\n", lstat( "fred", &sb)); > perror( "lstat"); > } > > If "fred" exists in the current directory, you would expect that errno > would not have been modified, and the output will be: > > lstat(fred) = 0 > lstat: Undefined error: 0 > > However, what comes out instead is: > > lstat(fred) = 0 > lstat: No such file or directory > > Indicating that lstat is diddling errno when it shouldn't be. 1: This is a classic programming error.. You're not really supposed to be looking at the value of errno except right after a -1 return from something. 2: the no such file or directory is actually stdio calling malloc, which is doing a readlink on /etc/malloc.conf, which probably doesn't exist. 3: You're calling stdio (ie: printf) *after* lstat() so you've gotten what's coming to you. :-) You're initializing the entire stdio system after calling lseek(). It's stdio that's leaking the errno. Cheers, -Peter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message