Date: Sat, 21 May 2005 21:13:29 +0100 From: Mark Murray <markm@FreeBSD.ORG> To: Steve Kargl <sgk@troutmask.apl.washington.edu> Cc: freebsd-standards@FreeBSD.ORG Subject: Re: Read /dev/null differs from POSIX Message-ID: <200505212013.j4LKDTMC070728@grovel.grondar.org> In-Reply-To: Your message of "Sat, 21 May 2005 12:36:05 PDT." <20050521193605.GB51782@troutmask.apl.washington.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
Steve Kargl writes: > >From http://www.opengroup.org/onlinepubs/009695399/toc.htm > > /dev/null -- An infinite data source and data sink. Data > written to /dev/null shall be discarded. Reads from > /dev/null shall always return end-of-file (EOF). > > This program ... abuses fread(3) return values. Try this: [grovel] ~ 09:10 pm $ cat test.c #include <stdio.h> int main(void) { int i, j; FILE *fp; j = -1; fp = fopen("/dev/null", "r"); while((i = fread(&j, sizeof(int), 1, fp))) { printf("i = %d\nj = %d\n", i, j); if (feof(fp)) break; } printf("AT END\ni = %d\nj = %d\n", i, j); return 0; } [grovel] ~ 09:10 pm $ gcc -Wall test.c -o test [grovel] ~ 09:11 pm $ ./test AT END i = 0 j = -1 [grovel] ~ 09:11 pm $ M -- Mark Murray iumop ap!sdn w,I idlaH
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200505212013.j4LKDTMC070728>