Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 07 Aug 2008 16:46:37 +0200
From:      Gabor Kovesdan <gabor@kovesdan.org>
To:        hackers@FreeBSD.org
Cc:        fjoe@FreeBSD.org
Subject:   strange issue reading /dev/null
Message-ID:  <489B0ACD.80008@kovesdan.org>

next in thread | raw e-mail | index | archive | help
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?

Thanks in advance,
Gábor



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?489B0ACD.80008>