Date: Thu, 7 Aug 2008 11:58:57 -0400 (EDT) From: Daniel Eischen <deischen@freebsd.org> To: Gabor Kovesdan <gabor@kovesdan.org> Cc: fjoe@freebsd.org, hackers@freebsd.org Subject: Re: strange issue reading /dev/null Message-ID: <Pine.GSO.4.64.0808071157101.8891@sea.ntplx.net> In-Reply-To: <489B0ACD.80008@kovesdan.org> References: <489B0ACD.80008@kovesdan.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 7 Aug 2008, Gabor Kovesdan wrote:
> Hello,
>
> I'm wondering why fgetc() returns 0xff if called with /dev/null:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int
> main(void)
> {
> int c;
> FILE *f;
>
> f = fopen("/dev/null", "r");
>
> if (c != EOF)
> printf("%c\n", fgetc(f));
> }
Hmmm, are you *sure* your code should not be written as follows:
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char **argv)
{
FILE *f;
int c;
f = fopen("/dev/null", "r");
if (f != NULL) {
c = fgetc(f);
if (c != EOF)
printf("%c\n", c);
else
printf("EOF encountered\n");
}
return (0);
}
--
DE
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.0808071157101.8891>
