Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!topaz!ll-xn!mit-amt!mit-eddie!genrad!decvax!decwrl!amdcad!amdimage!prls!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP Newsgroups: net.lang.c Subject: Re: Missing stdio features. Message-ID: <479@mcgill-vision.UUCP> Date: Sat, 9-Aug-86 06:35:33 EDT Article-I.D.: mcgill-v.479 Posted: Sat Aug 9 06:35:33 1986 Date-Received: Tue, 12-Aug-86 15:12:16 EDT References: <2340@robin.cs.nott.ac.uk> <7003@utzoo.UUCP> Organization: McGill University, Montreal Lines: 61 Keywords: stdio, buffering > 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@uw-beaver.arpa "Come with me a few minutes, mortal, and we shall talk." - Thanatos (Piers Anthony's Bearing an Hourglass)