Date: Wed, 17 Jun 1998 08:32:56 +0800 From: Peter Wemm <peter@netplex.com.au> To: Terry Lambert <tlambert@primenet.com> Cc: current@FreeBSD.ORG Subject: Re: Bogus errno twiddling by lstat... Message-ID: <199806170032.IAA06067@spinner.netplex.com.au> In-Reply-To: Your message of "Tue, 16 Jun 1998 23:55:32 GMT." <199806162355.QAA06852@usr02.primenet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Terry Lambert wrote:
> Try the following program:
>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <errno.h>
>
>
> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806170032.IAA06067>
