Date: Sat, 16 Nov 1996 02:29:19 +1100 From: Bruce Evans <bde@zeta.org.au> To: jgreco@brasil.moneng.mei.com, terry@lambert.org Cc: hackers@FreeBSD.ORG, jdp@polstra.com, scrappy@ki.net Subject: Re: Sockets question... Message-ID: <199611151529.CAA16817@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
>% man 2 read >(SunOS version) >... >READ(2V) SYSTEM CALLS READ(2V) > > system guarantees to read the number of bytes requested if > the descriptor references a normal file which has that many > bytes left before the EOF (end of file), but in no other > case. > >Key words, "but in no other case".. FreeBSD says the same thing in the same words except for English improvements. It lies :-). Short reads are possible even for normal files because the read might be into a partially invalid buffer. ffs_read() returns the blocks that are successfully read instead of unwinding the read and returning an EFAULT error. Example: --- #include <stdio.h> #include <stdlib.h> #define SIZE 0x10000 main() { void *buf; int n; buf = malloc(0x10000); n = read(0, buf, 0x10000); printf("read %d\n", n); } --- This prints 65536 here. A watertight example can be probably be constructed using mmap(). Short writes to normal files are more likely. They occur when the disk fills up and for partially invalid buffers. There are more serious problems for the latter case. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199611151529.CAA16817>