Missing stdio features.

mouse at mcgill-vision.UUCP mouse at mcgill-vision.UUCP
Sat Aug 9 20:35:33 AEST 1986


> I try to use stdio as often as possible for several reasons [...] but
> I feel it lacks one or two calls [...]
> a) comment on these
> b) mention their own pet stdio hates
> c) show portable ways to implement these
> d) tell me they're already implemented ==> RTFM.

> Addition:	fpending(fp)
(Henry Spencer comments that "the right solution to that is fselect(),
not fpending().".  I disagree; suppose you want to select on a FILE*
and on a file descriptor both?  How do you tell the difference?

> Addition:	finvbuf(fp)
I wanted this one, so I wrote it.  But I called mine fdumpbuf().

> Addition:	fslam(fp)
Interesting.  Never wanted it, though.

> Addition:	fbufsiz(fp), fbuftype(fp)
Never wanted 'em.

> An inconsistency - why is there no ungetchar(c) defined??
I have wondered.

Here are the things I have wanted badly enough to add to stdio:

fdumpbuf(FILE *f)
	Mentioned above, throws away the in-core buffer.

FILE *fopenfxn(int (*fxn)(), char *mode)
	Function-stream I/O.  Returns a FILE*, open for read or write
	(not both, "r+" is treated as "r").  When a character is
	written to (resp. read from) the stream, the function is
	called.  On write, the character written is passed as an
	argument; on read, the returned value is returned to the user
	(or to scanf etc).

FILE *fopenstr(char *str, int len, char *mode)
	An extension to sprintf() and sscanf().  This returns a stream
	which performs I/O to a string (this makes sprintf() and
	sscanf() unnecessay, though they are still convenient).

unfdopen(FILE *f)
	Undoes fdopen(), that is, closes the FILE* without close()ing
	the underlying file descriptor.

Unfdopen is trivial; fopenfxn and fopenstr are implemented by making
the stream appear unbuffered to putc and getc and then changing _flsbuf
and _filbuf to add the functionality.

Comments anyone?
-- 
					der Mouse

USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse
     think!mosart!mcgill-vision!mouse
Europe: mcvax!decvax!utcsri!mcgill-vision!mouse
ARPAnet: utcsri!mcgill-vision!mouse at uw-beaver.arpa

"Come with me a few minutes, mortal, and we shall talk."
			- Thanatos (Piers Anthony's Bearing an Hourglass)



More information about the Comp.lang.c mailing list