Read /dev/null differs from POSIX

Steve Kargl sgk at troutmask.apl.washington.edu
Sat May 21 12:36:10 PDT 2005


>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?

-- 
Steve


More information about the freebsd-standards mailing list