Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 May 2005 21:14:34 +0100
From:      Bob Bishop <rb@gid.co.uk>
To:        Steve Kargl <sgk@troutmask.apl.washington.edu>, freebsd-standards@freebsd.org
Subject:   Re: Read /dev/null differs from POSIX
Message-ID:  <6.2.0.14.2.20050521211303.04837368@gid.co.uk>
In-Reply-To: <20050521193605.GB51782@troutmask.apl.washington.edu>
References:  <20050521193605.GB51782@troutmask.apl.washington.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
At 20:36 21/05/2005, Steve Kargl wrote:
> >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
>
>   #include <stdio.h>
>   int main(void) {
>      int i=0,j;
>      FILE *fp;
>      fp = fopen("/dev/null", "r");
>      while(fread(&j, sizeof(int), 1, fp) != 1) {
>        i++;
>        if (i == 5) break;
>      }
>      printf("i = %d\n", i);
>      if (j == EOF)
>        printf("EOF\n");
>      else
>        printf("j = %d\n", j);
>}
>
>prints
>
>i = 5
>j = 1
>
>Is this historic BSD defacto behavior?

When fread hits EOF, it doesn't write to j.

--
Bob Bishop		    +44 (0)118 940 1243
rb@gid.co.uk		fax +44 (0)118 940 1295



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