Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!ukc!dcl-cs!nott-cs!jpo From: jpo@cs.nott.ac.uk (Julian Onions) Newsgroups: net.lang.c Subject: Missing stdio features. Message-ID: <2340@robin.cs.nott.ac.uk> Date: Mon, 28-Jul-86 07:42:19 EDT Article-I.D.: robin.2340 Posted: Mon Jul 28 07:42:19 1986 Date-Received: Wed, 30-Jul-86 00:42:37 EDT Reply-To: jpo@cs.nott.ac.uk (Julian Onions) Organization: Computer Science, Nottingham Univ., UK. Lines: 84 Keywords: stdio, buffering I try to use stdio as often as possible for several reasons (such as portability, efficiency, laziness ...) but I feel it lacks one or two calls to achieve some of the less every-day options. Most of these can be got around if you `know' the internal stdio structure - but that negates the portability win. Anyway, anyone care to 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) Synopsis: returns the number of characters that are buffered up on the stream pointed to by fp. Use: Has several uses, in particular useful when you are applying select(2) to a FILE, select may say there is nothing to read when in actual fact there is stuff buffered up. The only other way around this is to set buffering to 0 which is rather inefficient. It's trivial to add this as another macro. ------------------------- Addition: finvbuf(fp) Synopsis: invalidate in-core stdio buffer for FILE *fp. Use: If you know by other information that a file you currently have open has changed then you need to force a reread of the file ensuring that all buffered information is junked. The only safe/portable alternative is to fclose/fopen the file descriptor again which is reasonably expensive. It should probably not guarantee anything about the offset or else do a rewind(3). ------------------------- Addition: fslam(fp) Synopsis: shut the given descriptor in a hurry without flushing it. Use: If you know that flushing a descriptor will cause a block. e.g. you have a timeout writing to a terminal cos someones ^S'd it, so you decide to ignore that terminal & carry on. How can you shut it, fclose will try and flush the data and will hang the program again. If finvbuf() is in place this could be used instead. I suppose you could get around it with close(fileno(fp)); fclose(fp); but it seems a bit messy and may cause indigestion for the fclose routine. ------------------------- Addition: fbufsiz(fp), fbuftype(fp) Synopsis: fbuzsiz returns size of buffer in use, fbuftype indicates what sort of buffering is in use (none, line or full). Use: To determine whats going on dynamically. E.g. if( fbufsiz(stderr) == 0 || fbuftype(stderr) == _IONBF) { printf("stderr non buffered - fixing\n"); fclose(stderr); stderr = fdopen(2, "w") setbuf(stderr, buffer); } basically, you can set lots of interesting buffering modes but you can't discover whats in use. ------------------------- An inconsistency - why is there no ungetchar(c) defined?? Julian. jpo@cs.nott.ac.uk mcvax!ukc!nott-cs!jpo -- Julian Onions