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));
}
gcc foo.c
./a.out
ΓΏ
This causes a bug in BSD grep as /dev/null is not distinguished from
ordinary files in the code, thus I was expecting it just returned EOF,
but in reality this is not the case. How such cases should be handled?
You are testing c which has not been set. It works OK if you set c then
do the test:
+ c = fgetc(f);
if (c != EOF)
- printf("%c\n", fgetc(f));
+ printf("%c\n", c);
Sean
--
[EMAIL PROTECTED]
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"