From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 7 16:16:08 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 065431065680; Thu, 7 Aug 2008 16:16:08 +0000 (UTC) (envelope-from scf@FreeBSD.org) Received: from mail.farley.org (farley.org [67.64.95.201]) by mx1.freebsd.org (Postfix) with ESMTP id C15638FC0A; Thu, 7 Aug 2008 16:16:07 +0000 (UTC) (envelope-from scf@FreeBSD.org) Received: from thor.farley.org (HPooka@thor.farley.org [192.168.1.5]) by mail.farley.org (8.14.3/8.14.3) with ESMTP id m77G03mw056317; Thu, 7 Aug 2008 11:00:03 -0500 (CDT) (envelope-from scf@FreeBSD.org) Date: Thu, 7 Aug 2008 11:00:03 -0500 (CDT) From: "Sean C. Farley" To: Gabor Kovesdan In-Reply-To: <489B0ACD.80008@kovesdan.org> Message-ID: References: <489B0ACD.80008@kovesdan.org> User-Agent: Alpine 1.10 (BSF 962 2008-03-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="56599777-1628545831-1218124803=:1056" X-Spam-Status: No, score=-4.4 required=3.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail.farley.org 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 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:16:08 -0000 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --56599777-1628545831-1218124803=:1056 Content-Type: TEXT/PLAIN; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8BIT 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)); > } > >> 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 -- scf@FreeBSD.org --56599777-1628545831-1218124803=:1056--