From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 7 16:21:11 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2CBBA10656C8; Thu, 7 Aug 2008 16:21:11 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id DF4E78FC0C; Thu, 7 Aug 2008 16:21:10 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.3/8.14.3/NETPLEX) with ESMTP id m77Fwv8p019660; Thu, 7 Aug 2008 11:58:57 -0400 (EDT) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.0 (mail.netplex.net [204.213.176.10]); Thu, 07 Aug 2008 11:58:58 -0400 (EDT) Date: Thu, 7 Aug 2008 11:58:57 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Gabor Kovesdan In-Reply-To: <489B0ACD.80008@kovesdan.org> Message-ID: References: <489B0ACD.80008@kovesdan.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: fjoe@freebsd.org, hackers@freebsd.org Subject: Re: strange issue reading /dev/null X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Aug 2008 16:21:11 -0000 On Thu, 7 Aug 2008, Gabor Kovesdan wrote: > Hello, > > I'm wondering why fgetc() returns 0xff if called with /dev/null: > > #include > #include > > 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 #include 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