Backend for newlib's "scanf" family of functions

Eric Blake eblake@redhat.com
Wed Jul 23 23:43:00 GMT 2014


On 07/23/2014 03:07 PM, Scott L. Brookes wrote:

> How is scanf repackaged into read calls? Calling with a string format specifier, 
> there is no way to know how many bytes to ask for in the read. Expirementation 
> saw a read request for 1024 bytes, which would lead me to believe that it is up 
> to my pipe implementation to give only chars up to a whitespace, but how does 
> this jive with the POSIX definition of a read on a pipe? 

scanf, and in general ALL stdio read operations (such as fread()), are
programmed to call read() in chunks that default up to PIPE_BUF bytes in
length, but where you can tune the default request by any calls to
setvbuf().  Your read() implementation can return shorter than the
requested amount if the sending end does not have that much ready;
scanf() may not consume all the bytes it read()s, and will call read()
again if it needs to consume more.  Your best bet is to carefully
re-read the POSIX specifications of read() and write():

http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html

http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html

and make sure your implementation obeys those rules.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20140723/201ac21f/attachment.sig>


More information about the Newlib mailing list