Sub-optimal libc's read-ahead buffering behaviour

Peter Jeremy PeterJeremy at optushome.com.au
Thu Aug 4 07:57:45 GMT 2005


On Thu, 2005-Aug-04 10:39:09 +0400, Andrey Chernov wrote:
>So (considering changing content like /dev/mem too), any buferization is 
>potentially dangerous here. fseek traditionally used as buferization 
>break, in case, say, between fread and fwrite. In case SEEK_CUR still uses 
>the buffer, it probably should not for character device.

I can't see any reason for the current stdio behaviour:
- If you're accessing a device with "magic" behaviour then it's not safe
  to read(2) 4KB (or whatever) when userland asks to fread(3) 512 bytes.
- If the device doesn't have "magic" behaviour then you can just seek
  within the stdio buffer.

That said, I've seen similar behaviour on other systems so it could be
a subtle side-effect of POSIX.

-- 
Peter Jeremy


More information about the freebsd-current mailing list