tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: RFC - add snscanf(3) to stdio



On Sun, Aug 31, 2008 at 12:16:51PM +0200, Alan Barrett wrote:
 > > Is there a need for fsnscanf()? I'm not convinced but could be...
 > 
 > I assume you mean [v]fnscanf, which would read from an open file instead
 > of a memory buffer.
 > 
 > Is there a need?  Well, it's easy to imagine that the "f" versions of
 > these functions would be useful in parsing values from files with fixed
 > length fields.

Yeah, but you're almost certainly better off doing fread() followed by
sscanf(). Unless maybe you have a very large fixed-length field such
that you save significantly by not making an extra copy of it... but I
question whether such a thing exists in practice.

It doesn't follow that we should add every combination of
functionality that might conceivably be useful...

 > Is it a good idea?  Well, all the existing scanf-like functions appear
 > in all possible combinations of {read from stdin, read from an arbitrary
 > file, read from a memory buffer}.  I would suggest that, for symmetry,
 > any new scan-like functions should also follow that pattern.  So there
 > would be six new functions [v]{|f|s}nscanf to match the six existing
 > functions [v]{|f|s}scanf.

Well, yes, but the pattern also extends to printf. There's no
fnprintf(), and I don't think there's any compelling need for it
either.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index